cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 6 · After the tool › fence the result

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: fence the result

fence the result catches data being read as instructions.

Open: 11before loopopen ›Open: 22before modelopen ›Open: 33after modelopen ›Open: 44before toolopen ›Open: 55the toolopen ›Open: 66after toolopen ›Open: 77after loopopen ›Open: 88before replyopen ›It readsevery tool resultfence the resultrule · harnesspassCarries onfailIf it failsalways appliedWHERE IN THE CODE: fence() · H context/__init__.py:33-48
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. Wrap it in <<>> … <<>>.
  2. Escape any closing marker inside the data so it can't end the fence early.
It readsevery tool result
Kindrule
Provided byharness
If it failsalways applied
Where in the codefence() · H context/__init__.py:33-48
Runs at6 · After the tool
Real exampleGap F-131: the system prompt never explains the fence to the model.

More on this: Fencing.

How it is done: the real code

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

def fence(text: str, *, source: str) -> str:
    """Wrap untrusted content and neutralise attempts to close the fence early."""
    escaped = text.replace(FENCE_CLOSE, "<<<end untrusted [escaped]>>>")
    return f"{FENCE_OPEN.format(source=source)}\n{escaped}\n{FENCE_CLOSE}"