
Your Agent's Failures Are Underutilized Training Data
Chris Harper
2 min read
Jul 7, 2026 · 20:09 UTC
Your agent's worst runs contain the highest-signal data for making it better — but most teams discard them as one-off bugs instead of mining them as a dataset.
LangChain's engineering team published a post today making the case that systematic trace mining — not more prompt iteration — is the highest-leverage improvement path for production LLM apps. The core shift: stop treating agent failures as individual bugs to patch, and start treating them as labeled examples in a dataset.
The loop that most teams skip:
1. Instrument everything. If you're using LangSmith, Langfuse, or the Claude SDK's built-in event hooks, every tool call and intermediate step is already being captured. If not, add structured logging to your agent loop now — you can't mine what you don't record.
2. Write the slice query, not just "look at logs." Build a persistent filter that surfaces runs where your agent called the wrong tool, hallucinated a fact, failed to complete the task, or needed more than one retry. The pattern lives in the aggregate, not in any single run.
3. Label and build a dataset. Each failure is a negative example. Find or write the corrected version. Now you have input/output pairs — raw material for few-shot examples, prompt guardrails, or (when the pattern is pervasive) a fine-tune.
4. Close the loop. Update your prompt with concrete examples of the correct behavior. Add a guardrail for the top failure mode. If the same error appears in 30%+ of runs, that's a fine-tuning signal, not a prompt problem.
Applied to Claude Code automation. If you run Claude Code in a CI pipeline, PR review bot, or daily routine, trace which tasks consistently need retries or human correction. Filter status: error runs, export 20 examples, and review them. You'll typically find 3–4 root causes: vague CLAUDE.md instructions, missing tool permissions, context that's too short or too long, or a recurring ambiguous case. Fix those four — not one-offs.
A one-hour trace review session, done weekly, is worth more than a day of prompt iteration on examples that aren't drawn from production.
Sources: LangChain: Improving Agents is a Data Mining Problem | LangSmith evaluation docs | Langfuse tracing and evaluation