cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 8 · Before the reply

Agent Harness Tutorial · End to end · Zoom level 2

Check point 8: Before the reply

The very last look. It runs on direct answers too, so even approved templates are checked.

Where: on every path, templates included.

The strip at the top is the whole turn; the dark box is where you are. Click a check, or what it catches, to see how we took care of it. Dashed boxes are not built yet.
CheckCatchesKindProvided byIf it fails
no_promise_of_covera promise of coverruleagentsafe reply
no_pii_echopersonal dataruleagentsafe reply
money_in_rupeesthe wrong currencyruleagentsafe reply
name the referencea new claim without its CLM- numberruleagentnumber added

Only the three rules that need nothing but the reply text run here. The grounded rules need tool results, so they run after the model only.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

agent_harness/entrypoint/ending.py:127screened(): the last look, on every route
def screened(
    result: TurnResult,
    identity: Identity,
    rules: Mapping[pol.Position, tuple[pol.Rule, ...]] | None = None,
) -> TurnResult:
    """Every reply passes the reply guardrails before the customer reads it —
    whichever route produced it (F-020). One point, so the next template edit on
    any route is screened without anyone remembering to screen it. The verdict
    and the rule that fired are on the `agent.policy` span `enforce` opens.

    The agent's **configured** rules, not only the built-in ones: this read the
    defaults whatever it was given, so a deployment that added a reply rule was
    screened by the rules it had not configured (F-027)."""
    text = result.customer_message if isinstance(result, Failed) else result.reply
    verdict = pol.enforce(
        pol.Context(position=pol.Position.REPLY, identity=identity, text=text),
        None if rules is None else rules.get(pol.Position.REPLY),
    )
    if not verdict.blocked:
        return result
    # The words are replaced; what the turn *did* is not. An escalation that was
    # raised stays raised and an approval stays pending — replacing the result
    # type would drop the handoff the reply was about.
    if isinstance(result, Failed):
        return result.model_copy(update={"customer_message": pol.SAFE_REPLY})
    if isinstance(result, Completed):
        # A completion carries nothing but its words, and the words were
        # refused — so the result is a refusal. It used to stay `Completed`
        # with a `REFUSED` termination, which a caller branching on the type
        # read as a success (F-026, AHC-0017).
        return Refused(reply=pol.SAFE_REPLY, reason=verdict.reason, rule_id=verdict.rule)
    return result.model_copy(update={"reply": pol.SAFE_REPLY})

Look inside