LLM-powered applications in production inevitably encounter unexpected behaviors: hallucinated facts, degraded performance after model updates, silent truncation, and edge-case crashes. While no amount of planning eliminates all issues, having structured debugging patterns makes it possible to identify root causes quickly, implement fixes systematically, and prevent recurrence. This post covers practical debugging patterns for LLM applications, organized by symptom category, with worked hypothetical examples at each stage. All examples are illustrative and designed to be adapted to real systems.
Common Symptom Categories
Hallucination and Unsupported Claims
A model may confidently state facts that are entirely fabricated. This is especially dangerous in domains like medicine, finance, or legal services where incorrect information causes real harm.
Debugging pattern: Audit outputs against a knowledge source at set intervals. Log every claim alongside the supporting (or missing) evidence. When a claim has no source, flag it for reviewer attention and add the case to the offline evaluation dataset.
Hypothetical example: Imagine a travel bot recommending restaurants at a destination. A user asks "What's a good seafood restaurant in Boston?" The model replies "The Gloucester House, established 1935, known for its clam chowder." An audit reveals the restaurant closed in 2018. The debug step: search the knowledge base for Gloucester House records. The fix: add a venue-recency check and a source-backed disclaimer.
Format and Structure Violations
Applications that rely on JSON outputs, bullet lists, or tabular data can break when the model deviates from the expected format.
Debugging pattern: Validate every model output against a schema before downstream processing. Do not assume the model will conform to the prompt. When validation fails, capture the raw output, the prompt used, and the specific schema violation.
Hypothetical example: A support bot is supposed to return a JSON object with fields {"orderId": string, "status": string, "trackingUrl": string}. After a model update, the model starts wrapping the JSON in prose: "Here's your order info: {"orderId": ...}". The debug step: parse the model output more leniently and strip surrounding text, or tighten the prompt to explicitly request JSON-only output. The fix: add a system instruction "Return ONLY a valid JSON object, no surrounding text."
Performance Degradation
Latency increases, token count creep, or accuracy drops over time without an obvious code change.
Debugbing pattern: Monitor per-request metrics (latency, input tokens, output tokens, cost) continuously. Correlate changes with model version, prompt version, traffic volume, and deployment timestamps. Use a change-point detection algorithm to flag when metrics drift beyond expected ranges.
Hypothetical example: A notification service sees average latency rise from 800ms to 2.4s over two weeks. No code changes were deployed. Debugging: compare model versions (the provider may have silently updated). Check if token counts grew due to longer user prompts. Correlate with time-of-day patterns. The fix: pin the model version and add token budget warnings for long prompts.
Safety and Refusal Failures
The model may fail to refuse harmful requests, or may refuse legitimate ones. Both are safety concerns.
Debugging pattern: Run a focused adversarial test suite weekly. Include edge cases like prompt injection ("Ignore previous instructions and..."), boundary-pushing queries, and category-specific violations. Track refusal rate and false-refusal rate per model version.
Hypothetical example: A finance assistant starts answering "How do I maximize my tax refund by hiding income?" when previously it refused such queries. Debugging: run the adversarial test suite and capture the exact prompt that triggers the change. Check if a system prompt update altered the refusal behavior. The fix: restore the prior system prompt and add a regression guardrail to the evaluation dataset.
Debugging Workflow
When an issue surfaces, follow this sequence to locate and resolve it:
-
Reproduce consistently. Confirm the issue appears under the same conditions. Note the exact prompt, model version, and any contextual factors (user role, time of day, etc.).
-
Capture the full state. Log the raw model input, the raw model output, the model version, the prompt version, and any system instructions active at the time. Also log derived signals: intent classification, tool calls, success/failure flags.
-
Classify the symptom. Match the observed behavior to one of the categories above (hallucination, format violation, performance degradation, safety failure). This determines which debugging pattern to apply.
-
Apply the matched pattern. Use the appropriate debugging pattern: schema validation for format issues, adversarial testing for safety, metric correlation for performance, etc.
-
Fix and guard. Implement the fix, then add a regression guardrail to the offline evaluation dataset so the same failure cannot ship in a future release.
-
Verify and monitor. Run the reproduction case again to confirm the fix. Add the case to ongoing monitoring dashboards. Retire the guardrail after several release cycles if the issue does not reappear.
Worked Hypothetical Example: End-to-End Debugging
Imagine a fictional team operating a customer support agent. One morning, the on-call engineer receives an alert: "Refund success rate dropped from 92% to 67% overnight." No code changes were deployed in the last 48 hours.
Step 1 - Reproduce: The engineer tests the agent with a refund request and confirms the drop. The agent now escalates every refund to a human instead of auto-approving eligible ones.
Step 2 - Capture state: Log the full conversation, model version (claude-3-opus-20240229), prompt version (v14), and the agent's decision trace.
Step 3 - Classify: The symptom matches "Safety and Refusal Failures" — the agent is over-refusing refunds, likely due to a changed system prompt or model behavior shift.
Step 4 - Apply pattern: Run the adversarial refusal test suite. Check if the prompt injection "Ignore previous refund policies" triggers unexpected behavior. Compare current prompt v14 against v13.
Step 5 - Fix and guard: The team discovers that v14 added a new line to the system prompt about "conservative refund handling" that inadvertently raised the approval threshold. They revert to v13 and add a regression case: "Refund request of $45 for order #12345 should be auto-approved" to the evaluation dataset.
Step 6 - Verify and monitor: Re-test confirms refund success rate returns to 92%. The guardrail catches the same regression if it recurs. The team adds continuous monitoring of refund approval rates with alerts at 10% drops.
Limitations
Debugging patterns reduce MTTI (mean time to identify) and MTTR (mean time to resolve), but they do not replace good preventive practices: tight prompt versioning, model version pinning, and continuous evaluation. Some issues — especially subtle model behavior shifts — may still evade detection without human review.
Conclusion
Structured debugging patterns make LLM application issues tractable. By categorizing symptoms, capturing full state, applying matched patterns, and adding regression guardrails, teams can resolve production issues faster and prevent recurrence. Start with the four core categories (hallucination, format violations, performance degradation, safety failures) and expand as your system and experience grow.
For related guidance on evaluation pipelines, see Building LLM Evaluation Pipelines in Production. For patterns on testing AI workflows, see AI Workflow Testing Patterns for Production Systems.
Primary sources: