Lesson 43.4 · 4 of 5 · 5 min read · Reviewed 24 Nov 2026
Propagating errors instead of swallowing them
By the end, you can
- Return subagent failures as explicit errors with a reason.
- Explain why a swallowed error produces confident wrong answers.
Some of the most damaging agent bugs come from subagentsSubagent: A separate agent instance, with its own context and instructions, that a main agent delegates a task to. that fail quietly.
How it goes wrong
A subagent’s search tool times out. To be “helpful”, it reports “No relevant documents found.” The parent concludes nothing exists and writes a confident report that’s wrong. Nobody sees an error, because there wasn’t one.
Propagate the failure
Make failure explicit in what comes back:
{ "status": "error", "error": "search timed out after 2 retries", "retryable": true, "partial": ["doc-12"] }
Inside a tool loop, the same idea is is_error: true on the tool_resulttool_result: The content block you send back with the output of a tool, matched to the request by tool_use_id. (chapter 33). Distinguish empty (“I looked and there is nothing”) from failed (“I couldn’t look”).
What the parent does with it
With a real error the parent can retry, try another subagent or source, or tell the user plainly: “I couldn’t check the 2025 contracts; the archive search was down.” That honest gap is far better than a confident wrong answer.
Key points
- A subagent that hides a failure ("no results") makes the parent believe something false.
- Report errors explicitly: what failed, why, and whether a retry could help.
- The parent then retries, reroutes, or tells the user about the gap.
Make subagent failures impossible to miss
Return explicit, structured errors from subagents and make the parent treat 'empty' and 'failed' differently.
You will have: A subagent wrapper that turns exceptions into structured error results, and a parent that retries, reroutes or reports the gap.
Steps
- Read the three simulated searches: one finds documents, one finds nothing, one times out.
- Write run_subagent(search) that returns status ok with results, ok with an empty list, or error with a reason, retryable flag and any partial results.
- Never turn an exception into an empty result.
- Write the parent's handling: use results, accept a genuine empty, and for an error say plainly what could not be checked.
- Print the parent's final report.
Done when
- The timeout comes back as status error with retryable true.
- The genuine empty search is reported as 'nothing found', not as a failure.
- The final report says which archive could not be checked.
Open in the Playground No API key needed.
Starter code (Python)
def search_current(): return ["doc-12", "doc-31"]
def search_policies(): return []
def search_archive(): raise TimeoutError("archive search timed out after 2 retries")
def run_subagent(name, fn):
try:
docs = fn()
except Exception as e:
return {"name": name, "status": "ok", "results": []} # TODO: this hides the failure
return {"name": name, "status": "ok", "results": docs}
results = [run_subagent("current contracts", search_current), run_subagent("policies", search_policies),
run_subagent("2025 archive", search_archive)]
# TODO: the parent distinguishes found, empty and failed
for r in results:
print(r)
Show a solution
def search_current(): return ["doc-12", "doc-31"]
def search_policies(): return []
def search_archive(): raise TimeoutError("archive search timed out after 2 retries")
def run_subagent(name, fn):
try:
docs = fn()
except TimeoutError as e:
return {"name": name, "status": "error", "error": str(e), "retryable": True, "partial": []}
except Exception as e:
return {"name": name, "status": "error", "error": str(e), "retryable": False, "partial": []}
return {"name": name, "status": "ok", "results": docs}
results = [run_subagent("current contracts", search_current), run_subagent("policies", search_policies),
run_subagent("2025 archive", search_archive)]
report = []
for r in results:
if r["status"] == "error":
report.append(f"could not check {r['name']} ({r['error']}; retryable={r['retryable']})")
elif r["results"]:
report.append(f"{r['name']}: found {r['results']}")
else:
report.append(f"{r['name']}: looked, nothing found")
print("\n".join(report))