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.
How we took care of it.
- Wrap it in <<
>> … << >>. - Escape any closing marker inside the data so it can't end the fence early.
| It reads | every tool result |
| Kind | rule |
| Provided by | harness |
| If it fails | always applied |
| Where in the code | fence() · H context/__init__.py:33-48 |
| Runs at | 6 · 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}"