aeat.entrypoints.mcp._faithfulness module¶
Faithfulness check: agent narration must not invent numeric tax values.
A documented failure mode of financial MCP agents is fabricating a plausible
numeric result when uncertain. This PostToolUse check extracts amount-shaped
numbers from the agent’s narration and flags any whose digit sequence is absent
from the preceding tool-result JSON. It is advisory by default - relaying a
warning - and a hard block on the irreversible filing-handoff path, mirroring the
no-silent-under-declaration discipline of warning where legitimate cases exist
and blocking where the consequence is irreversible. It never computes a value; it
only checks that every number the agent states came from a tool result.
- class FaithfulnessResult(**data)[source]¶
Bases:
BaseModelVerdict of one faithfulness check.
faithfulis true when every amount-shaped number in the narration is grounded in the tool JSON.blockingrecords whether this check ran on the irreversible handoff path;flagged_valueslists the ungrounded numbers.- faithful: bool¶
- blocking: bool¶
- flagged_values: tuple[str, ...]¶
- faithfulness_check(*, agent_text, tool_result_json, blocking=False)[source]¶
Flag amount-shaped numbers in
agent_textabsent fromtool_result_json.- Parameters:
- Return type:
- Returns:
FaithfulnessResultwith the advisory or blocking verdict.
- class SessionGroundingWindow(*, max_results=32)[source]¶
Bases:
objectA bounded, in-memory record of the session’s tool-result JSON.
The serving-path integration surface (ADR R6): the model’s free narration lives client-side where the server cannot see it, so the ENFORCEABLE faithfulness boundary is the tool-call arguments — every amount-shaped number an agent sends INTO a call must be grounded in a tool result this same session produced. The window accumulates each call’s result JSON (memory only, never persisted — results carry taxpayer figures and
sensitive-financial-data-secure-storage-onlyforbids writing them outside secure storage) and serves as the grounding corpus forarguments_faithfulness().Bounded FIFO so a long session cannot grow without limit; the bound is generous because a grounding figure is almost always from the immediately preceding calculate/revision reads.
- Parameters:
max_results (int)
- arguments_faithfulness(*, arguments_json, window, blocking)[source]¶
Check a tool call’s ARGUMENTS against the session’s grounding window.
The serving-path enforcement point: advisory on ordinary mutating calls, a hard block at the export / record-marker handoff (an amount the session never produced must not enter the irreversible artefact call). An empty window with amount-shaped arguments on the handoff path blocks — figures from nowhere are exactly the fabrication this gate exists to stop.
- Return type:
- Returns:
- Parameters:
arguments_json (str)
window (SessionGroundingWindow)
blocking (bool)
- advisory_line(result)[source]¶
The warning line the server prepends to a result for an advisory mismatch (client-relayed, localized).
- Return type:
- Parameters:
result (FaithfulnessResult)