By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A coordinator sends three questions to three subagents. The database subagent times out twice. The search and writer subagents return. The coordinator merges what it has, finds a hole in the revenue row, and fills the hole with last quarter's figure from its own context. The report reads well. The figure was never retrieved for this quarter, and nothing in the output says so.
A retry is safe only when the operation is idempotent and the error says a repeat could succeed. Idempotent means that repeating the call has the same effect as calling once. A blanket retry damages three things. It hides how often the tool fails. It adds latency the caller never sees. And a success after two failures carries no history, so nobody learns that the data arrived late.
A structured error is a value your code can branch on, not a sentence a human reads. Three fields do most of the work, and a fourth makes the error replayable.
| Field | The question it answers | Example |
|---|---|---|
origin | Which agent called which tool | analyst/sql_runner |
code | What went wrong, in a vocabulary your code matches on | timeout |
retryable | Could repeating the call succeed? | true |
input_ref | What produced it, small enough to replay | query:region_q3 |
Add provenance to the result, not only to the error. Provenance is the record of which agent, which tool and which input produced a claim. Without it, a merged report is a pile of sentences that no reviewer can trace back to a source.
The snippet defines the error once and keeps it attached to the claim it blocked. The merge returns three things: the supported claims, the explicit gaps, and a partial flag. Every layer above the merge reads the same shape, so no layer has to guess what happened below it.
from dataclasses import dataclass
@dataclass
class ToolError:
origin: str # which agent called which tool
code: str # machine-readable reason
retryable: bool # may a repeat succeed?
input_ref: str # what produced it, small enough to replay
@dataclass
class Claim:
text: str
source: str
error: ToolError | None = None
def merge(claims: list[Claim]) -> dict:
supported = [c.text for c in claims if c.error is None]
gaps = [
{"missing": c.text, "origin": c.error.origin, "code": c.error.code}
for c in claims
if c.error is not None
]
return {"supported": supported, "gaps": gaps, "partial": bool(gaps)}
report = merge(
[
Claim("Q3 revenue was 4.1M", "annual_report.pdf p.12"),
Claim(
"Q3 revenue by region",
"sales_export.csv",
ToolError("analyst/sql_runner", "timeout", True, "query:region_q3"),
),
]
)
print(report)A partial answer with an explicit gap is a usable product. An invented number is a liability, because it looks exactly like a real one. The rule is blunt: never fill a gap with a plausible value. Report the gap, name what is missing, and let the caller decide what to do with the part that is supported.
Add an attempt counter and a limit of two attempts to the merge function. Then call it twice: once with a claim whose error is retryable, and once with the same claim marked not retryable. Produce a two-row table: the error, whether it was retried, and what the caller sees. You are done when a non-retryable error is never retried, and a failed retry leaves one gap rather than two.
Key takeaways
A structured error carries an origin, a code and a retryable flag, plus the input that produced it.
Retry only idempotent operations whose error says a repeat could succeed, and cap the attempts.
Provenance, meaning the agent, tool and input behind a claim, belongs on successful results too.
Return partial results with explicit gaps instead of inventing a value or retrying silently.
Let the error travel beside the claim it blocked, all the way to the caller.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.