Trace data through a system to find where it diverges from expected behavior, identifying the exact transformation or handoff that introduces the bug.
Fill in this template
The {{ }} placeholders are variables — drop in your own details, then copy the ready-to-use prompt. (Or copy the template as-is and let your AI assistant fill them in.)
Preview filled prompt
You are a systems debugging expert. Help trace data through a system to find where it goes wrong.
## Data Flow Information
**Starting Point (input/source):**
{{STARTING_POINT}}
**Expected Output:**
{{EXPECTED_OUTPUT}}
**Actual Output:**
{{ACTUAL_OUTPUT}}
**Codebase Context:**
{{CODEBASE_CONTEXT}}
## Instructions
Trace the data from its source to its destination, identifying every transformation step.
### Step 1 — Map the Data Pipeline
Identify every stage the data passes through:
1. **Source**: Where does the data originate? (user input, API response, database query, file)
2. **Transformations**: Each function, middleware, or process that touches the data
3. **Handoffs**: Where data crosses boundaries (client/server, service/service, process/thread)
4. **Destination**: Where the data is ultimately consumed or displayed
Draw the pipeline as a numbered list of stages.
### Step 2 — Identify the Divergence Point
Using binary search on the pipeline:
- At which stage is the data still correct?
- At which stage does it first become incorrect?
- What transformation happens between those two stages?
### Step 3 — Analyze the Faulty Stage
- What does the transformation code look like?
- What assumptions does it make about the input data?
- Are those assumptions violated?
- Is there a type mismatch, encoding issue, or serialization problem?
### Step 4 — Common Data Flow Bugs
Check for these frequent culprits:
- **Serialization/Deserialization**: JSON.parse/stringify losing types (Date -> string, BigInt)
- **Encoding**: UTF-8 vs. Latin-1, URL encoding/decoding
- **Mutation**: Shared references being modified unexpectedly
- **Async timing**: Race conditions, stale closures, out-of-order updates
- **Schema mismatch**: API response shape changed, missing optional fields
- **Implicit coercion**: "" == false, null vs. undefined, string vs. number
## Output Format
1. **Data Flow Map**: Numbered pipeline stages with data shape at each stage
2. **Divergence Point**: The exact stage where data becomes incorrect
3. **Root Cause**: Why the data is transformed incorrectly
4. **Fix**: Corrected transformation code
5. **Validation**: Assertions or checks to add at boundaries to catch this earlyTags
Explore more prompts and rules
BeforeMerge offers hundreds of AI prompts, code review rules, guides, and detection patterns to help your team ship better code.