bugger.
APPLIED AI / PRACTICAL GUIDE

How to debug applied AI systems

You have built a RAG application or an agent. Now practice explaining why it fails. These three original Python labs use fixed retrieval data, simulated tool effects and recorded evaluation outcomes. No live model, API key or GPU is required. The evidence is reproducible so you can distinguish a failure in application logic from uncertainty in model behavior.

1. Start with an observable contract

Replace “the AI gave a bad answer” with a statement you can check. Which document should have reached the context? How many committed actions should one request produce? Which examples belong in an evaluation denominator? Write the expected outcome before inspecting the implementation.

Keep the smallest input and the history needed to reproduce the symptom. Record the request identity, relevant configuration and component outputs. Change one assumption at a time, then predict what evidence would disprove your hypothesis. A plausible final answer alone cannot establish that an agent took the right actions.

  • Name the first observable mismatch.
  • Preserve the relevant input and prior events.
  • Choose a check that can distinguish the suspected causes.

2. Retrieval: follow scores back to document identity

Start with the retrieval-ranking lab. Inspect the query, candidate document IDs and score values before changing a prompt. A relevant document can exist in an index and still be omitted or ranked incorrectly when a score is interpreted backward or a score becomes detached from its document.

A similarity and a distance have different ordering contracts. Cosine similarity compares vector direction through a normalized dot product; read the actual producer’s contract before choosing a sort. Carry the document identity with its score through ranking and selection. Use contrasting scores, reordered candidates, ties and a requested result count to make the intended ordering visible.

  • Write the score unit and which direction means closer.
  • Keep each score attached to the candidate that produced it.
  • Verify expected document IDs, then preserve ordinary ranking cases.

3. Tool calls: distinguish a timeout from a failed action

In the agent-idempotency lab, follow the operation through invocation, effect commit, response loss and retry. A caller timeout only describes what the caller observed. The tool may already have changed state. Check the simulated effect log as well as the agent’s received result.

An operation identity should survive retries of the same intent while distinct requests remain distinct. A retry mechanism must respect the tool’s idempotency contract. In a real service, recording that identity and committing its effect need a suitable atomic boundary; an in-memory teaching replay does not establish crash safety or concurrency safety for production. The AWS Builders’ Library describes both retry side effects and request-parameter mismatch handling.

  • Mark when the effect commits and when the caller learns its result.
  • Test a response lost after commit and a later retry.
  • Protect different operations that happen to have the same arguments.

4. Evaluation: inspect the population behind the number

In the evaluation-batches lab, compare the aggregate with the per-example outcomes. A mean of batch means gives small and large batches equal influence. Failed examples can also disappear from a denominator and make a system look better as its failures increase. Write the declared treatment of failures and empty inputs before repairing the arithmetic.

Repartition the same examples into unequal batches and compare the result. Keep a case with a valid zero score, a failed example and an empty batch so missing values cannot be confused with successful zero-valued observations. The evaluator itself needs regression tests; a consistently computed score still needs a rubric that measures the behavior your users need.

  • Name exactly which examples contribute to the numerator and denominator.
  • Compare several partitions of the same evaluation population.
  • Report failures explicitly and retain the stated empty-input policy.

5. Locate the first broken boundary in the trace

Read the supplied evidence in order. For retrieval, compare candidate identity and score with the selected context. For an agent, compare calls, returned observations and committed state. For evaluation, compare example outcomes, batch summaries and the final report. Stop at the earliest point where the contract breaks rather than repairing only its final symptom.

Use a short table with step, component, input, output and expected invariant. The labs provide constructed evidence for investigation, and your Run results provide observations from your current code snapshot. Those two sources answer different questions: the scenario explains the reported failure, while a new execution tells you whether your repair satisfies the checks.

  • Separate an execution observation from a constructed scenario.
  • Check intermediate state and final outcome together.
  • Keep the case that falsified your first hypothesis.

6. Finish with a repair you can explain

Make the smallest repair that restores the shared invariant. Run the visible reproductions, add a focused custom case and submit against the official regression checks. Passing a Run is useful investigation evidence; an accepted Submit records completion and unlocks the explanation. Compare your reasoning with the explanation after you have tested your own hypothesis.

Write three sentences in your own notes: what assumption failed, how that assumption produced the observed symptom, and which regression would catch it again. Include an ordinary control that your change could have broken. This is the useful output of practice: a causal explanation supported by a reproducible check.

  • Keep one original failure and one nearby valid control.
  • Tie the regression to the failed assumption.
  • State the limits of what the passing checks establish.

7. When the model itself can vary

These labs isolate deterministic application bugs. A live-model investigation needs additional evidence: a versioned evaluation dataset, recorded model and configuration versions, and repeated trials where run-to-run variation matters. Preserve the actual inputs, outputs and tool observations needed to compare trials. A fixed replay teaches a mechanism; it cannot measure a live model’s reliability.

Evaluate correctness, answer quality, cost and latency separately. Use objective assertions for effects and explicit contracts, and calibrate any judgment-based rubric against representative human review. Avoid relying on one exact sentence or one uncalibrated model judge. Anthropic’s agent-evaluation guidance distinguishes the execution transcript from the final environment outcome and recommends multiple trials for variable behavior.

  • Version the dataset, model, prompt and relevant settings.
  • Repeat trials and report variation where it affects the claim.
  • Keep quality, correctness, cost and latency as separate measurements.

Frequently asked questions

How do you separate model issues from application bugs in RAG or agents?
Freeze the retrieval vectors, tool responses, or recorded model outputs first. If the wrong document is selected or a tool executes twice on fixed inputs, the defect is in your deterministic application code rather than model randomness.
Do I need an OpenAI or Anthropic API key to practice these AI debugging labs?
No. Bugger’s Applied AI labs use fixed vectors, simulated tool effect logs, and recorded evaluation outputs in standard-library Python so you can reproduce and test fixes deterministically.

Further reading

Start with primary reports and documentation. Community discussions are discovery leads, not evidence on their own.

PUT THE METHOD TO WORK

Practice on a focused challenge.

Explore Applied AI challenges
BUILD A REGULAR PRACTICE

Start free. Keep following the evidence.

Explore the current challenge collection, or see what is planned for future practice packs.