$ fssg build --deterministic --validate |

How to Fault-Test an AI Agent Before Production

AI Engineering

A happy-path evaluation tells me that an agent can succeed. It does not tell me whether the system fails safely.

That difference matters because an agent run is not one model call. It is a chain of context assembly, inference, tool selection, external I/O, state mutation, retries, grading, and reporting. A correct final answer can hide a broken tool call. A failed final answer can originate in stale state rather than weak reasoning. If I test only task success, I learn the symptom and miss the failure boundary.

I therefore treat fault injection as part of agent evaluation. Before production, I deliberately remove evidence, delay tools, corrupt non-authoritative state, duplicate responses, and break evaluators. The goal is not to make the model look bad. The goal is to prove that each subsystem has a defined failure behavior.

Start with the invariant, not the fault

Random disruption produces dramatic logs and weak conclusions. A useful test starts with an invariant: something the system must preserve even when one dependency misbehaves.

For example:

If the customer record cannot be read,
then the agent must not issue a refund,
and the run must end with a reviewable abstention.

This statement gives the test a shape. The injected fault is “customer record unavailable.” The expected behavior is not “the agent should still solve the task.” It is “no refund effect, explicit abstention, evidence of the failed read, and a named recovery path.”

The invariant also separates model quality from system quality. The model may propose a refund from incomplete context. The runtime must still deny the effect. This is the contract at the center of an AI engineering runtime: generation proposes; the surrounding system owns authority and consequences.

Use a four-plane fault matrix

I divide an agent run into four planes. Each plane needs different faults and different assertions.

Plane Injected fault Required evidence Safe behavior
context missing policy, stale retrieval, truncated input context version, retrieval status, omission marker abstain, request data, or narrow the claim
tools timeout, malformed response, wrong schema, duplicate delivery tool span, attempt ID, schema error, effect ID retry only when safe; never duplicate an effect
state stale checkpoint, conflicting memory, failed write state version, transition record, conflict details reject the transition or enter recovery
evaluation grader unavailable, contradictory scores, missing oracle evaluator version, raw result, disagreement mark outcome unresolved; do not promote

This matrix prevents a common mistake: treating every failure as a prompt problem. A timeout is not repaired with a more persuasive system message. A duplicate side effect is not an evaluation issue. A stale checkpoint is not model hallucination.

The same symptom can cross several planes. Suppose an agent uses an outdated refund policy. The cause may be missing context, a retrieval cache, persistent memory, or a grader that accepted an unsupported answer. The first unrecovered event matters more than the final label. I use that principle in failure localization: repair ownership begins where the system first failed to contain the problem.

Give every test a fault card

I keep each fault scenario small enough to run repeatedly. A fault card can be plain YAML:

id: tool-timeout-before-write
plane: tools
precondition: refund is eligible
inject:
  target: payments.lookup
  behavior: timeout
  attempt: 1
assert:
  - no_call: payments.issue_refund
  - terminal_state: needs_review
  - trace_contains: tool.timeout
  - evidence_contains: payments.lookup
recovery:
  allowed: [retry_lookup, human_review]
  forbidden: [guess_from_cached_total]

The card is more useful than a generic “robustness score” because it names the boundary, expected artifact, and forbidden behavior. It can run in CI against a deterministic tool double, in staging against an isolated service, or in replay against captured input envelopes.

A strong suite includes negative assertions. no_call: payments.issue_refund is often more important than the final text. Agent systems create risk through effects, not only through sentences.

For mutating tools, the harness should replace the real adapter with an effect recorder. The recorder accepts the same typed request but produces no external mutation. If the scenario needs a real integration, use an isolated account and a unique effect identifier. A timeout after a write is especially important: the agent may not know whether the operation happened. Retrying without stable effect identity can convert uncertainty into a duplicate charge, message, or deletion. The crash window is explained in Effect IDs Before Retry.

Inject faults at boundaries, not inside prose

A prompt such as “pretend the database is unavailable” tests role-playing. It does not test the database boundary.

I prefer injection points that sit where the real failure would occur:

  • the context builder omits a required document and records the omission;
  • the tool proxy delays or corrupts a typed response;
  • the state store rejects a compare-and-swap transition;
  • the evaluator returns unavailable or two incompatible verdicts;
  • the event bus redelivers the same message;
  • the authorization layer denies an otherwise plausible action.

This keeps the experiment honest. The model sees the same class of evidence it would see during an incident. The runtime must react through its real contracts, not through a theatrical sentence embedded in the task.

OpenTelemetry's GenAI work is useful here because it pushes model calls, tool calls, agent operations, errors, and token usage into a shared trace vocabulary. Tracing does not create correctness, but without linked spans it is difficult to identify which injected fault produced which downstream behavior. The test should assert on trace structure as well as output.

Separate three outcomes

A fault test should not collapse into pass or fail too early. I use three outcomes:

  1. Contained: the system detected the fault, preserved the invariant, and produced a recovery artifact.
  2. Degraded: the task could not finish, but no unsafe effect occurred and the limitation is explicit.
  3. Escaped: the fault crossed its boundary and produced an unsupported claim, invalid transition, duplicate effect, false success, or misleading evaluation.

“Degraded” is not automatically bad. If required evidence is unavailable, stopping may be the correct behavior. What matters is whether the stop is timely, visible, and actionable.

The escape class should name the violated invariant. “Answer quality dropped” is too vague. “Refund was proposed without a current policy record” points to a specific contract. “Evaluation marked the run successful after the grader timed out” points to a false-completion defect.

Build the minimum suite

I would not begin with hundreds of scenarios. A minimum production gate can start with eight:

  1. required context missing;
  2. retrieved fact stale;
  3. tool timeout before mutation;
  4. timeout after an ambiguous mutation;
  5. malformed tool response;
  6. duplicate event delivery;
  7. state-version conflict;
  8. evaluator unavailable.

For each scenario, verify the terminal state, external effects, trace, evidence bundle, and recovery path. Then add domain-specific faults around the actions with the largest blast radius.

AWS AgentCore documents dataset evaluation as running agents against scenario sets and evaluating the results, while online evaluation samples deployed sessions. Those are useful execution modes. The engineering step I add is explicit fault control: the scenario must state what was broken, which invariant must hold, and which artifact proves containment.

What this does not prove

Fault injection does not prove that the scenario distribution matches production. It cannot reveal every emergent interaction, and a deterministic tool double may omit timing or authorization behavior found in the real service. Evaluators can also share the same blind spots as the system they judge.

That is why I do not turn the suite into a universal reliability percentage. I use it as a boundary map. Each passing scenario says: under this fault, with this configuration, the system preserved this invariant and produced this evidence.

That is already a strong result. A production agent should not be defined only by what it can do when everything works. It should also be defined by what it refuses to do, what it records, and how it returns control when one part of the loop stops being trustworthy.

Sources

FACET AI CLI Terminal
facet@ai:~$