Prompt
My agent keeps giving the wrong answer in prod. How do I troubleshoot it?
Latest observation
Here’s a practical way to troubleshoot an agent that’s giving wrong answers in production.
1) Reproduce the bad case exactly
Start with the exact user prompt, plus anything the agent received around it:
- conversation history
- system/developer prompts
- tool outputs
- retrieved documents
- model name/version
- temperature/top_p
- tool configuration
- memory/state
If possible, run the same input in a staging/debug environment so you can inspect every step.
2) Determine where the failure happens
Break the agent into stages and test each one:
A. Input / prompt construction
Check whether the final prompt sent to the model is what you expect:
- missing instructions
- truncated context
- duplicated messages
- bad formatting
- wrong system prompt
- stale memory included
B. Retrieval / grounding
If it uses RAG or tools:
- did it retrieve the right docs?
- were docs relevant but incomplete?
- did chunking split important context?
- are embeddings/search filters working?
- are citations or source selection off?
C. Tool use
If the agent calls tools:
- did it call the right tool?
- were arguments correct?
- did the tool return an error or partial data?
- did the agent ignore tool output?
- is the tool output being parsed incorrectly?
D. Model behavior
If inputs are correct, the model may be:
- hallucinating
- overconfident
- not following instruction hierarchy
- failing on ambiguity
- sensitive to temperature or sampling settings
3) Add observability
You want a trace for every run. Log:
- request ID / trace ID
- raw user input
- final prompt/messages
- retrieved context
- tool calls + arguments + outputs
- model response
- latency and token usage
- errors/retries/fallbacks
- model version and config
If you can, store full run traces for bad examples and a small sample of good ones.
4) Compare good vs bad runs
Take one good answer and one bad answer for similar inputs. Diff them:
- prompt differences
- retrieval differences
- tool output differences
- model config differences
- context length differences
This often reveals the issue quickly.
5) Check for common production-specific causes
A lot of “works in test, fails in prod” issues come from:
- context window overflow: important messages get truncated
- prompt injection from retrieved content or user input
- stale cached answers
- wrong environment config or API keys
- model drift if the provider updated the model
- non-determinism due to temperature > 0
- timeouts causing partial tool results or fallback behavior
- race conditions in memory/state
- locale/timezone/unit mismatches
- post-processing bugs that rewrite or strip the model output
6) Create a minimal test case
Strip the agent down until it fails in the smallest possible setup:
- same prompt
- no extra memory
- one tool at a time
- one retrieved document at a time
- temperature 0
This helps isolate whether the problem is in:
- prompt design
- retrieval
- tools
- orchestration
- the model itself
7) Add evals and regression tests
Once you find a failure, turn it into a test:
- input
- expected behavior
- required sources/tools
- failure mode
Run this in CI or nightly against fixed model/config versions. This prevents reintroducing the bug.
8) Use guardrails for production
If wrong answers are costly, add:
- confidence thresholds
- “I don’t know” behavior
- citation requirements
- tool-result validation
- constrained outputs / schemas
- human escalation for ambiguous or high-risk cases
9) A good debugging workflow
A reliable sequence is:
- Capture failing trace
- Re-run in staging with full logging
- Diff against a successful trace
- Identify whether failure is prompt, retrieval, tool, or model
- Fix the narrowest cause
- Add a regression test
- Monitor after deployment
10) If you want, I can help you debug a specific trace
If you paste:
- the user prompt
- system/developer prompt
- retrieved context
- tool calls/results
- the wrong answer
- the correct answer you expected
…I can help you pinpoint the likely failure point and suggest a fix.