Threat Modeling Compound AI Systems › Code: assembling the full analysis harness

Michael BrenndoerferDecember 2, 20267 min read
Language AI HandbookAll chapters
Part 61 of 67Agentic AI and Protocol Security
Chapter 465Threat Modeling Compound AI Systems › Code: assembling the full analysis harness
Reading section 11 of 15 · Code: assembling the full analysis harness · 7 minSection 11 of 15 · 7 min

Section 11 of 15 · 7 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The first replay checks the matrix's four named data rows against the two projected dictionaries and the declared application record. The edit row records that neither architecture exposes an editing operation. A second check reports whether each view still carries the selected location and whether the title and staff note have the intended visibility.

PythonIn [14]
CollapseExpand
field_names = {
    "Title": "title",
    "Room": "room",
    "Shelf": "shelf",
    "Staff note": "staff_note",
}
checked_data_rows = []
for label, field in field_names.items():
    assert hasattr(record, field)
    destinations = tuple(
        "Model input" if field in context else "Application only"
        for context in (public_context, location_context)
    )
    checked_data_rows.append((label, *destinations))
assert matrix[:-1] == checked_data_rows

design_checks = {
    "both supply the intended location": all(
        context["room"] == record.room and context["shelf"] == record.shelf
        for context in (public_context, location_context)
    ),
    "only full public view supplies the title": "title" in public_context
    and "title" not in location_context,
    "both keep the staff note out of the model": all(
        "staff_note" not in context
        for context in (public_context, location_context)
    ),
}
assert all(design_checks.values())
for property_name, holds in design_checks.items():
    print(f"{property_name} | {holds}")
ConsoleOut [14]
CollapseExpand
both supply the intended location | True
only full public view supplies the title | True
both keep the staff note out of the model | True

A useful follow-up for a real catalog team would be to turn those properties into a release test that inspects the actual model request. Include a second fixture whose location is missing and check that the renderer reports that state. The fixture here only exercises the case where room and shelf are present. Its passing checks say nothing about network configuration, storage guarantees, or which fields a separate service records in logs.

Turn assumptions into small defensive checks

Start with a replay that exercises the same entry under two explicitly different permission assignments. Verify that the authorized projection contains the documented fields and the route with no permission returns the documented denial. Exercise empty selections and changed source records separately. This gives the tester a concrete expectation without involving any live model or production resource. Keep the data small enough that a reviewer can derive the expected output on paper.

A second test compares route conformance. For a known caller-visible entry, capture the actual fields sent at the model boundary in a test run. Assert the exact allowed key set and check that protected fields never cross it. Verify the output audience separately. For example, the same test should distinguish an answer rendered in the intended session from a response that is never shown. A missing display event cannot be interpreted as evidence that the data boundary worked; the context inspection supplies the evidence for that boundary.

A test report should explain which parts of the system it observed. The toy checks above operate on a dictionary constructed from a known record. They do not run the application that owns identity and storage. Detailed checks of external implementation can be added when inspecting a real repository. Start with the component named in the threat model and trace it to the normal call path, including any background variants. That makes changes to the map auditable when a future engineer moves the boundary or adds a new fallback.

Keep fixtures and modeling assumptions in version control with the corresponding design description. A changed expected key set in a test can be a purposeful feature decision. The reviewer should be able to read the change and confirm which authority and data decisions it affects. An unchanged test should still fail if the capability or fields exceed the approved scope. Adjust the invariant when requirements change and state why it changed.

A replay for a missing location

Run one more defensive replay using the library's room assignment workflow. In this fixture a source value can be missing during a shelf move. That is an input-state problem, and the scope of both context projections stays the same. The application should show an unavailable status unless it has a designated partial-result policy. This replay represents unavailable as a missing selection in memory. The function accepts only a context dictionary and returns either a pair of strings or no pair. It does not read the catalog or attempt to repair the source value.

PythonIn [15]
CollapseExpand
def complete_location(context: dict[str, str]) -> tuple[str, str] | None:
    room = context.get("room")
    shelf = context.get("shelf")
    if not room or not shelf:
        return None
    return room, shelf


missing_shelf = {"room": record.room, "shelf": ""}
assert complete_location(public_context) == ("East", "E4")
assert complete_location(location_context) == ("East", "E4")
assert complete_location(missing_shelf) is None
assert complete_location({}) is None

The replay is deliberately small. The function checks presence, and its empty-string convention matters to the test. It treats a nonempty string as present. A real catalog may need to normalize whitespace or validate that a shelf code belongs to the room. If the library defines these conditions, a test should name the validator that enforces them and show a known-valid location and one lacking the required relation. Presence alone establishes only the property we checked above.

You can make a second comparison independent of field coverage. Suppose the recorded room is East in the catalog and the application receives a proposed West, E4. The test can treat the proposed pair as fixture data and reject it because the validated source pair differs. Use a typed interface for proposal fields so the comparison does not have to guess where a room name sits in free-form text.

PythonIn [16]
CollapseExpand
def matches_selected_location(
    proposed: tuple[str, str], context: dict[str, str]
) -> bool:
    location = complete_location(context)
    return location is not None and proposed == location


assert matches_selected_location(("East", "E4"), location_context)
assert not matches_selected_location(("West", "E4"), location_context)
assert not matches_selected_location(("East", "E4"), missing_shelf)

This test deliberately compares the proposal with the record. If the record is outdated, equality can accept an outdated answer. That limitation tells the reviewer where to add another check. It is a question about catalog maintenance rather than about the type of the proposal or which fields the renderer is allowed to read.

Read the matrix from the perspective of different owners

A library systems administrator can start at the asset column, locate the disputed field, and check what got across the model boundary. A catalog operator can start at the source first and check whether the record matched the physical location at the time it was updated. The two investigations might end up in the same review, but they ask for different evidence. To investigate a stale shelf, the operator might ask for a record update time. To investigate model scope, the application owner needs the shape of the actual context request. The observed update time cannot establish the context shape.

A review can ask all three questions using a single benign replay while recording different observations. First, does the current reader pass the read check? Second, which fields does the answering component see? Third, does the displayed position match the selected reply data? Collect each answer where the predicate was checked. If the system only records that a request succeeded, it cannot supply any of these distinctions later. If it stores the entire record to supply all distinctions at once, that introduces a new data flow that merits review.

The most practical change log for this exercise traces the changed cell back to an owner and a requirement. If location-only starts carrying the title, explain which task now needs it. If staff note starts reaching another component, identify what rule makes that transfer legitimate and whether the component's access scope is appropriate. If the renderer is replaced, inspect the new component's audience binding and output check separately. This is the kind of maintenance threat modeling supports: specific questions about changed responsibilities rather than redoing a generic checklist from memory.

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