Models, Retrieval, Tools, and Control Flow › Testing failure boundaries

Michael BrenndoerferDecember 2, 20265 min read
Language AI HandbookAll chapters
Part 64 of 67Compound AI System Design
Chapter 485Models, Retrieval, Tools, and Control Flow › Testing failure boundaries
Reading section 7 of 11 · Testing failure boundaries · 5 minSection 7 of 11 · 5 min

Section 7 of 11 · 5 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Each fixture changes one condition. The unsupported query ends before retrieval. A deliberately incorrect generator loses its answer when the citation names a product that retrieval found but the size filter removed. The empty catalog returns no results. A price limit equal to a catalog price also gives no match under the exclusive rule.

We then exercise the reservation gate. An availability question does not propose a reservation. The same reservation is declined without permission, gets recorded with permission and stock, and cannot get recorded with unknown stock. The fixture still reports two units afterward.

PythonIn [15]
CollapseExpand
def cite_filtered_product(
    products: tuple[Product, ...],
) -> tuple[str, tuple[str, ...]]:
    return "Trail Runner Lite", ("p2",)
PythonIn [16]
CollapseExpand
reservation = Reservation("p1", "10")
unsupported = run_assistant("Tell me a joke", STOCK)
rejected = run_assistant(QUERY, STOCK, generate=cite_filtered_product)
assert unsupported.trace == ("parse", "parse_rejected")
assert rejected.trace[-1] == "attribution_rejected"
assert rejected.outcome is Outcome.ABSTAIN
assert set(bm25_rank("trail runner", CATALOG)) == {"p1", "p2"}

The same stock entry can exist when a catalog search has no candidates, including the empty-catalog case. An early return means that a later inventory stage never gets a product ID it could use. The tests also treat a whole-dollar amount equal to the item's price as out of scope for the request. Change “under” to “at most” in a production language contract and update both the predicate and the equality-boundary test.

PythonIn [17]
CollapseExpand
assert run_assistant(QUERY, STOCK, catalog=()).product_ids == ()
assert run_assistant(QUERY.replace("$120", "$110"), STOCK).product_ids == ()
PythonIn [18]
CollapseExpand
assert available.simulated_reservation is None
assert (
    run_assistant(
        QUERY, STOCK, reserve_requested=reservation
    ).simulated_reservation
    is None
)
assert (
    run_assistant(
        QUERY, STOCK, reserve_requested=reservation, allow_effects=True
    ).simulated_reservation
    == reservation
)
assert (
    run_assistant(
        QUERY, None, reserve_requested=reservation, allow_effects=True
    ).simulated_reservation
    is None
)

Two negative controls make the permission check more useful. Allowing the effect does not allow changing the requested size. And with an available inventory fixture, a missing stock entry represents zero and prevents the record. With no fixture at all, the availability state is instead unknown and the entire decision exits through partial service.

PythonIn [19]
CollapseExpand
assert (
    run_assistant(
        QUERY,
        STOCK,
        reserve_requested=Reservation("p1", "9"),
        allow_effects=True,
    ).simulated_reservation
    is None
)
assert (
    run_assistant(
        QUERY, {}, reserve_requested=reservation, allow_effects=True
    ).simulated_reservation
    is None
)
assert STOCK == {("p1", "10"): 2}

A parser can also return a record that is structurally present but unusable. These two cases exercise validation and the documented exception boundary separately. Both fail before retrieval. Adapters that connect to an external model are outside this example and would translate transport or decoding failures into the local interface's supported outcomes.

PythonIn [20]
CollapseExpand
def missing_size(_: str) -> QueryPlan:
    return QueryPlan(Intent.AVAILABILITY, "trail runner", None, 120)


def malformed_parse(_: str) -> QueryPlan:
    raise ValueError("unreadable plan")
PythonIn [21]
CollapseExpand
assert (
    run_assistant(QUERY, STOCK, parse=missing_size).trace == unsupported.trace
)
assert (
    run_assistant(QUERY, STOCK, parse=malformed_parse).trace
    == unsupported.trace
)
assert (
    run_assistant(QUERY.replace("$120", "$120.50"), STOCK).outcome
    is Outcome.ABSTAIN
)
assert (
    run_assistant(QUERY.replace("size 10", "size 10.5"), STOCK).trace
    == unsupported.trace
)
assert run_assistant("Trail Runner size 10.5", STOCK).trace == unsupported.trace
for unsupported_size in ("10 1/2", "10-1/2", "10 ½"):
    mixed_size = QUERY.replace("size 10", f"size {unsupported_size}")
    assert run_assistant(mixed_size, STOCK).trace == unsupported.trace
for unsupported_price in ("120 1/2", "120-1/2", "120 ½"):
    mixed_price = QUERY.replace("$120", f"${unsupported_price}")
    assert run_assistant(mixed_price, STOCK).trace == unsupported.trace
assert (
    run_assistant("Trail Runner size 10 or size 10.5", STOCK).trace
    == unsupported.trace
)
assert (
    run_assistant("Trail Runner under $120 or under $110.50", STOCK).trace
    == unsupported.trace
)

assert (
    run_assistant("Is the Trail Runner available in size 10.", STOCK).outcome
    is Outcome.COMPLETE
)

Where each path stops

The matrix marks whether each fixture visited a component. The rejected-citation path reaches validation and stops before the stock lookup. The partial path reaches the lookup, then returns its reduced outcome. The available and partial rows have the same visited stages. Read the outcome or inspect the trace to distinguish success from unavailability at the last stage.

PythonIn [22]
CollapseExpand
stages = ("parse", "retrieve", "filter", "generate", "validate", "lookup")
fixtures = (
    ("Unsupported", unsupported),
    ("Rejected citation", rejected),
    ("Available", available),
    ("Stock unknown", partial),
)
visited = [
    [int(stage in answer.trace) for stage in stages] for _, answer in fixtures
]
VisualizationOut [23]
CollapseExpand
Visited stages for unsupported, rejected citation, available, and stock-unknown paths.
The unsupported fixture visits only parsing. The rejected citation stops after validation. The available and stock-unknown fixtures reach inventory lookup, with distinct outcomes.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy