Validate agent responses
Ask for structured output and validate it before using it in your application.
Ask for a JSON answer
Section titled “Ask for a JSON answer”Define a JSON response contract to receive data your application can validate. The agent writes the answer inside the requested tag, and Outpost parses and validates it before exposing result.value.
API reference: DispatchResult and defineJsonResponse.
Write the brief for the tag
Section titled “Write the brief for the tag”Outpost sends your brief unchanged: it adds no format instructions. Say which tag to use and show an example of its content, as above.
dispatch() checks that the brief contains the opening tag (<verdict>) before a sandbox starts. A missing tag fails with a configuration error.
Validate with a parsing function
Section titled “Validate with a parsing function”A function receives the parsed JSON as unknown and returns the typed value. Throw to reject it. read() applies the same rules as dispatch(), so you can test a response offline.
The last complete <verdict>…</verdict> pair wins, so a draft earlier in the answer is ignored. Its content is trimmed and may be wrapped in a json code fence.
Return plain text
Section titled “Return plain text”defineTextResponse() returns the trimmed text inside the tag, without JSON parsing.
Handle an invalid answer
Section titled “Handle an invalid answer”A missing tag, invalid JSON or a schema rejection makes dispatch() throw a ResponseError with code response, once no repair turn is left.
API reference: ResponseError.
Let the agent repair its answer
Section titled “Let the agent repair its answer”Set repairs to give the agent more turns after an invalid answer.
Each repair resumes the same conversation with the validation error and the previous content. It asks for the corrected tag only, without editing files or running commands. Repair turns add to result.usage and result.text.
Repairs need an agent that can continue its conversation; dispatch() refuses repairs otherwise. Choose an agent shows which harnesses can.
Limits
Section titled “Limits”- A dispatch with
responseruns one pass:passesmust be 1 or omitted. - A tag starts with a letter, followed by letters, digits,
_or-. - A valid response proves its shape, not its claims. Check “tests passed” by running the tests in a sandbox session or a verification loop.
API: defineJsonResponse · defineTextResponse · ResponseError · ResponseSpec · DispatchResult.