TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/mattpocock/sandcastle/llms.txt
Use this file to discover all available pages before exploring further.
Output helper lets you extract a structured payload from an agent’s response. Instead of parsing the agent’s free-form text yourself, you instruct the agent to emit its answer inside a named XML tag, and Sandcastle locates the tag, parses the content, validates it against your schema, and returns it as a typed field on result.output.
Both Zod and Valibot schemas work because Sandcastle uses the Standard Schema interface under the hood — any library that implements StandardSchemaV1 is supported.
Import
Output.object() — JSON with schema validation
Use Output.object() when the agent should return structured data. The agent emits JSON inside the configured XML tag, Sandcastle parses it and validates it against your schema, and the inferred type flows through to result.output.
Signature
The XML tag name the agent will emit its JSON inside. For example
"result" expects the agent to produce <result>{"key":"value"}</result>. The resolved prompt must contain the literal opening tag <result> — if it does not, run() throws before starting the sandbox.A Standard Schema validator (Zod, Valibot, etc.) used to validate the parsed JSON. The inferred output type becomes the type of
result.output.Output.string() — plain string extraction
Use Output.string() when you only need the raw text inside the tag, with no JSON parsing or schema validation.
Signature
The XML tag name. Tag contents are whitespace-trimmed and returned as a plain string — no JSON parsing, no schema validation.
Type definitions
OutputObjectDefinition<T>
OutputStringDefinition
OutputDefinition
output field on RunOptions.
StructuredOutputError
StructuredOutputError is thrown by run() when structured output extraction or validation fails. Possible failure modes:
- The configured XML tag was not found in the agent’s stdout (
rawMatchedisundefined). - The tag contents failed
JSON.parse(causecarries the parse error). - The parsed JSON failed schema validation (
causecarries the Standard Schema issues array).
The XML tag that was searched for.
The raw string content found between the opening and closing tags.
undefined when the tag was not found in stdout at all.The underlying parse or validation error. A JSON
SyntaxError for parse failures, or a Standard Schema issues array for validation failures.Commits the agent created during the run. Available even when output extraction fails.
The branch name the agent worked on.
Host path to the preserved worktree, if the worktree had uncommitted changes.
Constraints
maxIterationsmust be1(the default). PassingoutputwithmaxIterations > 1throws before the sandbox starts.- The resolved prompt must contain the opening tag literal — for example
<result>. If the tag is not present in the prompt,run()throws before starting the sandbox. Output.string()andOutput.object()both requiremaxIterations === 1.- Standard Schema support covers Zod, Valibot, and any other library that implements
StandardSchemaV1.