Skip to content

Interview question · Agent Loops & the Harness

A weather tool returns a 500 and the agent answers with a temperature anyway. Fix the harness.

The model did not malfunction; it filled a gap the harness left open. The fix spans the error contract, the retry policy and a grounding check on the final answer.

mediumNewUpdated Nov 2026

TL;DR: Three harness changes, in order of strength: retry transient failures inside the dispatcher so the model rarely sees them; return the failures that remain as explicit observations ("no data, do not estimate"); and check the final answer so any figure it states must appear in a tool result from this run. Then keep the run as an eval case.

How to approach it

Get the trace first and ask what the model actually received when the tool failed. The answer decides the fix: an empty string, a Python exception message, a generic "error" and a well-formed error object lead the model to different places. Then ask whether the 500 was transient, because the cheapest fix for a flaky dependency is a retry the model never sees.

A strong answer

Trace
How a 500 became a temperature
  1. 01user"Do I need a coat in Pune this evening?"
steps 0tool calls 0writes 0context 0 tok
1/5

user

"Do I need a coat in Pune this evening?"

The model is not the first wrong step. The dispatcher caught the 500 and returned an empty string, so from the model's point of view the tool returned nothing, and a model asked a question with nothing to go on will often answer from priors. Fixing it means changing what the harness does at three points.

1. Retry what is transient, where the model cannot see it. A 500, 502, 503 or a timeout on an idempotent read gets two or three retries with exponential backoff and jitter inside the dispatcher, within a per-tool budget. Most transient failures end here, and the model's transcript never fills with noise.

2. Make the remaining failures explicit observations. When retries are exhausted, the result should say what happened and what the model may and may not do:

{
  "error": "weather_unavailable",
  "retryable": false,
  "message": "No weather data for Pune right now. Do not estimate; say so and
              suggest checking again later."
}

The retryable flag tells the model whether calling again could help, which also prevents the opposite failure, a model hammering a dead service.

3. Check the answer against the run. For agents that report facts from tools, a cheap deterministic grounding check catches the residue: every number in the final answer must appear in some tool result from this run. It is crude, it has false positives you will tune, and it catches exactly this incident.

import re

def ungrounded_numbers(answer, tool_results):
    seen = set(re.findall(r"-?\d+(?:\.\d+)?", " ".join(tool_results)))
    return [n for n in re.findall(r"-?\d+(?:\.\d+)?", answer) if n not in seen]

results = ['{"error": "weather_unavailable", "retryable": false}']
print(ungrounded_numbers("It'll be about 24°C, no coat needed.", results))  # => ['24']

results = ['{"city": "Pune", "temp_c": 19, "rain_chance": 0.6}']
print(ungrounded_numbers("19°C with a 60% chance of rain.", results))  # => ['60']

The second example shows the tuning: the tool said 0.6 and the answer said 60%, so the checker needs unit-aware normalisation before it gates anything. Start it in report-only mode, read what it flags, and promote it to blocking (send the answer back with what was ungrounded) once its false-positive rate is acceptable.

Finally, add this exact run to the evaluation set with the tool stubbed to fail, and grade it on the end state: the answer must say the data was unavailable and contain no invented figure.

What interviewers probe next

"Why not just tell the model in the system prompt never to make up data?" Keep that line, it lowers the rate. It cannot be the fix, because a prompt changes probabilities and the incident lived in the dispatcher's empty string.

"The same tool fails for every user during an outage. What changes?" The per-tool circuit opens fleet-wide, the dispatcher returns the unavailable result immediately without calling the dependency, and an alert fires. Retrying per run during a known outage only adds load.

"Which errors should go back to the model rather than being retried?" Errors the model can act on: an invalid argument, an unknown city name, a date out of range. Those go back with what was wrong and the valid values.

How it's scored

Weak: Adds "do not hallucinate" to the prompt, or retries the tool forever.

Hire: Separates transient from terminal errors, retries the transient ones with backoff, and returns the rest as explicit, structured observations.

Strong Hire: Finds the swallowed error as the first wrong step, adds a grounding check on the final answer with a plan for its false positives, keeps a circuit breaker for outages, and turns the run into a stubbed-failure eval case.

Common mistakes

  • Catching every exception in the tool and returning "ok", which also hides the failure from the harness's retry logic.
  • Returning raw stack traces, which cost tokens and give the model nothing to act on.
  • Retrying non-idempotent tools the same way as reads.
  • Shipping a grounding check straight into blocking mode without measuring what it wrongly rejects.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.