Skip to lesson

NVIDIANVIDIA-Certified Professional: Agentic AI2026-102.4 Implement error handling (retry logic, graceful failure recovery).

Route failures to the right owner

Completed by the knowledge check

Learning objective

Classify failures and decide whether to return them to the LLM as observations or raise them to the caller.

Core idea

A failed tool call can contain useful information for the next reasoning step, or it can signal that execution must stop. Choose the recipient by asking who can change the condition safely. A model can correct a malformed search query. It cannot restore an expired service credential, repair a broken dependency, or establish whether a timed-out payment committed.

Returning an observation keeps the agent loop alive and spends more inference tokens. Raising an exception transfers control to the caller, where deployment recovery, cancellation, and business reconciliation belong. Neither choice turns failure into success. See 1.2.2 for the ReAct loop itself; this lesson decides what information crosses its failure boundary.

How it works

Classify cause, repairability, and outcome certainty

Create a failure-policy table for each tool before exposing it to the agent. Record the failure category, whether another attempt is safe, the permitted recipient, and the terminal outcome. Keep outcome certainty separate from cause: a network timeout can be transient while the result of a write remains unknown.

Use the following distinctions when implementing that policy:

FailureDeciding conditionMechanism and recipientCost or risk
Correctable tool inputThe model can supply a valid alternative without extra authorityReturn a sanitized tool observation with the invalid field and permitted correctionAnother model turn and validation pass
Valid business rejectionThe request is valid but the operation is unavailable under business rulesReturn a domain result, such as no matching inventoryThe model must not report completion
Temporary dependency failureRepeating the operation is safe and fits the remaining budgetAdapter retry policy; raise after exhaustionExtra traffic and elapsed time; see 2.4.2
Authorization or configuration defectRepair requires an operator or caller decisionRaise a classified exception to the callerRequest fails until the owner fixes the cause
Ambiguous write outcomeThe remote system might have committedCaller reconciliation using the operation identifierDuplicate side effects if blindly repeated; see 2.4.4
CancellationThe caller no longer wants executionPropagate asyncio.CancelledError after cleanupContinued work wastes capacity and can create unwanted writes

These are application policy categories, not NVIDIA exception class names. The adapter must translate its dependency’s actual response into the chosen category. Do not infer retry safety from the exception’s text alone.

Configure the NVIDIA failure boundary

Choose the error boundary for the configured agent; the three agents below require nvidia-nat[langchain]. For ReAct, use pass_tool_call_errors_to_agent; see 1.2.2 for its loop and recovery budgets. The defaults differ by agent:

Agent _typeError control and defaultFailure destination
react_agentpass_tool_call_errors_to_agent: trueErrors go to the agent; false raises an exception
tool_calling_agenthandle_tool_errors: trueTool errors are caught and returned in a ToolMessage so the agent can retry
rewoo_agentraise_tool_call_error: trueRaises immediately; false includes the error message in the tool response passed to the next tool

ReWOO also documents tool_call_max_retries with a default of 3. Do not transfer a retry count or error-handling flag from one agent to another. These workflow controls do not replace classification inside the tool adapter.

For a ReAct workflow that mixes correctable input errors and privileged writes, return expected, safe domain outcomes explicitly from the adapter and configure unexpected tool exceptions to escape with pass_tool_call_errors_to_agent: false. This prevents an infrastructure exception from becoming another model instruction. The adapter owns which information it returns; the workflow owns whether uncaught tool exceptions reach its caller.

Model-output parsing failures have a separate recovery budget; see 1.2.2.

Preserve useful information without leaking internals

A repair observation should identify the attempted operation, the invalid input, and the allowed next step. For example, an application-defined result can say that date_range exceeds the permitted reporting interval and request a shorter range. The error should not expose service credentials, full stack traces, or an unrestricted alternate endpoint.

In the toolkit, function middleware can preprocess inputs, postprocess outputs, and short-circuit execution. The documented FunctionMiddleware.function_middleware_invoke interface receives call_next; an adapter or wrapper can validate before calling it and translate expected failures into safe results. Keep unexpected exceptions visible to the caller rather than converting every exception into an answer-shaped string.

Cancellation is neither a repair observation nor a classified dependency failure: propagate it after cleanup (see 1.8.2).

Key distinctions and trade-offs

An observation changes the agent’s next decision; a retry repeats an execution path. A corrected query is a different input, while repeating a timed-out request unchanged is a transport recovery attempt. Count and measure those separately so that a small tool retry limit does not hide repeated model-directed calls.

A business rejection is also different from a runtime exception. An unavailable reservation is a valid result that the assistant can explain. An inability to contact the reservation service is an execution failure. Converting both into “not available” produces false business information and sends the wrong signal to operations.

Passing errors to the model improves recovery only when the model has the information and authority needed to repair them. Raising everything loses useful interactive correction; returning everything hides defects and increases token consumption. The tool owner defines expected domain failures, while the workflow owner chooses the escaping-exception policy.

Architecture / decision scenario

A hospital employee assistant prepares staff-training reports. It has a six-second response target and two tools: a read-only report search and an enrollment writer. Search rejects date ranges longer than 31 days; enrollment requires a service identity and can modify an employee’s record. These are deployment requirements, not toolkit defaults.

A proposed design returns every exception to the model because it can reformulate requests. The application architect rejects that blanket policy. A 60-day search becomes a sanitized observation requesting a range of at most 31 days. The adapter uses an application-defined, request-scoped correction_attempts counter to permit one corrected search call; if that call is also invalid, it raises to the caller instead of returning another repair observation. An enrollment authorization failure escapes to the caller and alerts the service owner; another prompt cannot grant the missing permission.

If enrollment times out after submission, the caller uses the stored enrollment operation identifier to reconcile its status before another write. The assistant reports that enrollment is unconfirmed. It does not turn the timeout into an invitation to try a different employee identifier. pass_tool_call_errors_to_agent: false handles uncaught exceptions, while expected search corrections remain ordinary adapter results. The tool owner tests each category, and the workflow owner verifies that the six-second budget includes any corrective model turn.

Common exam traps

  • Treating every exception as useful model feedback.
  • Treating a valid business rejection as proof that the dependency failed.
  • Assuming a tool retry limit also bounds model-directed corrections or elapsed time.
  • Returning raw exception strings that expose credentials or operational details.
  • Swallowing cancellation and continuing side-effecting work.
  • Reporting an unknown write outcome as either confirmed success or confirmed failure.

What to remember

Send the model only failures it can safely act on. Return expected domain outcomes deliberately, raise infrastructure and authority failures to their owner, and preserve uncertainty after ambiguous writes. Configure the selected agent’s error boundary explicitly and keep cancellation separate from ordinary recovery.

Knowledge check

References