Tool, Retrieval, and Memory Poisoning › Tool poisoning: schemas, descriptions, and implementations

Michael BrenndoerferDecember 2, 20267 min read
Language AI HandbookAll chapters
Part 61 of 67Agentic AI and Protocol Security
Chapter 467Tool, Retrieval, and Memory Poisoning › Tool poisoning: schemas, descriptions, and implementations
Reading section 3 of 11 · Tool poisoning: schemas, descriptions, and implementations · 7 minSection 3 of 11 · 7 min

Section 3 of 11 · 7 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A tool definition and a tool result cross different boundaries. The definition tells the host and model how to describe an available operation. The result supplies data after the call. Review definition revisions before exposing them to the model, and validate results against the approved contract before using them elsewhere. A compromised implementation can return an incorrect value that still conforms to a result schema.

JSON Schema can express structural constraints on a document. Passing those checks establishes conformity to the schema being used. For example, a catalog lookup can accept a syntactically valid item identifier while the caller lacks access to the item it names. Enforce the access decision in the host or service that owns the operation. Keep the policy inputs, such as the authenticated caller, under the application's control. JSON Schema Validation, Draft 2020-12

In revision 2026-07-28 of the Model Context Protocol (MCP), clients must treat tool annotations from untrusted servers as untrusted. Maintain the host's approved capability classification independently of the tool's own description. If a tool advertised as a lookup is approved for reading only, the effect boundary should enforce that restriction. MCP Tools, revision 2026-07-28

Schema checks and independent authorization

A narrow schema makes code review easier because the reviewer can follow a small set of known argument shapes. Restrict optional fields to those you need. Use explicit types, ranges and allowed identifiers where the product contract permits them. Enforce structural rules with the declared schema and enforce access rules against verified caller identity and the actual resource. Keep their results separate in logs so an operator can explain why a call stopped.

Suppose a catalog administrator investigates a disputed lookup. A trace may show that the tool accepted a valid item code. The relevant decision is whether the caller was authorized for that particular item at that time. The shape check narrows the accepted input contract. The resource service uses current authoritative state to decide access. If the schema evolves, review its effects on both accepted documents and the resource checks the tool needs.

Description and result review

Compare tool descriptions to the approved service contract when a definition enters the catalog or receives a revision. For a tool with side effects, use a host-side classification based on verified policy. If the host cannot establish the effect boundary, restrict what the tool can do. A description may express intended behavior but an implementation can change independently, so preserve the approved definition revision and the implementation or deployment evidence paired with it.

Review how the host handles results. A schema can tell us whether an item status belongs to an accepted set. Whether that specific status is current for the actual item depends on evidence from the resource provider. If a result arrives without the required identity or freshness evidence, avoid automatically merging it into an approved source or writing it to durable memory. Instead review which inputs the operation had and what data it returned. The local example below checks typed arguments and compares mock policy decisions for invented records.

A worked example: schema validation versus authorization

The fixture defines a small lookup schema and checks each proposed call against it. Calls that pass go to a separate policy check using mock caller entitlements.

PythonIn [3]
CollapseExpand
import json

# Inert tool schema: a fictional account lookup with a constrained id format.
TOOL_SCHEMA = {
    "name": "lookup_account",
    "parameters": {
        "type": "object",
        "properties": {
            "account_id": {"type": "string", "pattern": "^acct-[0-9]{4}$"},
            "region": {"type": "string", "enum": ["us", "eu"]},
        },
        "required": ["account_id"],
        "additionalProperties": False,
    },
}

This hand-written validator receives an already decoded mapping from the fixture. It checks field types, an anchored pattern, an enum, required keys and extra keys. A production adapter would first enforce the top-level object requirement. The exercise shows the order of field checks before authorization.

PythonIn [4]
CollapseExpand
import re


def validate_call(schema, call):
    params = schema["parameters"]
    props = params["properties"]
    errors = []
    # required keys
    for key in params.get("required", []):
        if key not in call:
            errors.append(f"missing required: {key}")
    # no extra keys
    if params.get("additionalProperties") is False:
        for key in call:
            if key not in props:
                errors.append(f"unexpected key: {key}")
    # per-property checks
    for key, value in call.items():
        spec = props.get(key, {})
        if "type" in spec and not isinstance(value, str):
            errors.append(f"{key}: wrong type")
        if "pattern" in spec and isinstance(value, str):
            if not re.fullmatch(spec["pattern"], value):
                errors.append(f"{key}: pattern mismatch")
        if "enum" in spec and value not in spec["enum"]:
            errors.append(f"{key}: not in enum")
    return errors


assert validate_call(TOOL_SCHEMA, {"account_id": "acct-0001"}) == []
assert validate_call(TOOL_SCHEMA, {"account_id": "acct-0001" + chr(10)}) == [
    "account_id: pattern mismatch"
]

The six fixtures include one permitted request and one well-formed request for an account outside the caller's allowed region. The program gets the mock entitlements from its caller context. The proposed call supplies account and optional region values.

PythonIn [5]
CollapseExpand
# Caller context is a separate, trusted input, not something the model supplies.
CALLER = {"role": "support", "entitled_regions": ["us"]}

# Inert records mapping account -> owning region (fictional).
ACCOUNT_REGIONS = {"acct-0001": "us", "acct-0002": "eu", "acct-0003": "us"}


def authorize_call(call, caller):
    reasons = []
    acct = call.get("account_id")
    region = ACCOUNT_REGIONS.get(acct)
    if region is None:
        reasons.append("unknown account")
    elif region not in caller["entitled_regions"]:
        reasons.append("region not entitled")
    req_region = call.get("region")
    if req_region is not None and req_region != region:
        reasons.append("region mismatch")
    return reasons
PythonIn [6]
CollapseExpand
calls = [
    {"account_id": "acct-0001"},  # valid + authorized
    {"account_id": "acct-0002"},  # valid shape, unauthorized region
    {"account_id": "acct-9999"},  # valid shape, unknown account
    {"account_id": "acct-0001", "region": "eu"},  # valid shape, region mismatch
    {"account_id": "bad-format"},  # pattern failure
    {"account_id": "acct-0001", "debug": True},  # extra property
]

for call in calls:
    schema_errs = validate_call(TOOL_SCHEMA, call)
    auth_errs = (
        authorize_call(call, CALLER) if not schema_errs else ["(skipped)"]
    )
    print(
        json.dumps(call),
        "-> schema:",
        schema_errs or "ok",
        "| auth:",
        auth_errs or "ok",
    )
ConsoleOut [6]
CollapseExpand
{"account_id": "acct-0001"} -> schema: ok | auth: ok
{"account_id": "acct-0002"} -> schema: ok | auth: ['region not entitled']
{"account_id": "acct-9999"} -> schema: ok | auth: ['unknown account']
{"account_id": "acct-0001", "region": "eu"} -> schema: ok | auth: ['region mismatch']
{"account_id": "bad-format"} -> schema: ['account_id: pattern mismatch'] | auth: ['(skipped)']
{"account_id": "acct-0001", "debug": true} -> schema: ['unexpected key: debug'] | auth: ['(skipped)']

The output shows the critical gap. {"account_id": "acct-0002"} passes schema validation cleanly (it is a well-formed account id) yet authorization rejects it because the caller is not entitled to the EU region.

The matrix distinguishes authorization failure from an authorization check that never ran. Review the schema row before interpreting the authorization row.

PythonIn [7]
CollapseExpand
# Recompute the two-check outcome for each candidate call, deterministically.
call_rows = []
for call in calls:
    schema_errs = validate_call(TOOL_SCHEMA, call)
    auth_errs = (
        authorize_call(call, CALLER) if not schema_errs else ["(skipped)"]
    )
    call_rows.append(
        {
            "call": json.dumps(call),
            "schema_ok": not schema_errs,
            "auth_ok": (not schema_errs) and (not auth_errs),
        }
    )
matrix = [
    [int(row["schema_ok"]) for row in call_rows],
    [int(row["auth_ok"]) if row["schema_ok"] else 2 for row in call_rows],
]
VisualizationOut [8]
CollapseExpand
Two rows compare schema and authorization. Four calls pass schema, only call 1 passes authorization, and the last two skip authorization.
Schema and authorization checks for six fictional requests. Two fail schema and never reach authorization.

The valid shape checks do not provide region entitlements. In this fixture four calls pass the schema. Of those four, one is authorized. For the final two, the schema check fails and authorization is skipped. In a deployment the service still applies authorization before using the requested resource. Choose and document the order of validation and access checks with its disclosure policy in mind: the fact that a resource exists can itself be sensitive in some systems. The plot makes the skipped state explicit so an investigator can distinguish a policy reason from an operation that never reached the policy check.

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