You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(agent): validate structured outputs after generation with one retry
The agent block never checked structured output after generation:
processStructuredResponse was a bare JSON.parse whose failure path logged,
attached an unread _responseFormatWarning, and returned success via the
standard-format fallback. Downstream blocks read the structured fields as
undefined, indistinguishable from a legitimate empty answer. Models with
native structured outputs are additionally constrained only by a weakened
grammar (the SDK transform strips enum, minLength, numeric bounds, and
similar keywords into advisory prose), and prompt-based models had no
enforcement at all.
Validation now runs in the provider-request seam whenever the response
format's existing strict flag is not false (the default the block schema
has always documented): truncation at the output token limit (read from
the final model trace segment every provider already populates),
unparseable JSON (with a Markdown code-fence rescue), and ajv validation
against the authored schema are one failure condition. A failed attempt
on a tool-free request is resampled once, with the failed attempt's
tokens, cost, and trace segments folded into the final result; requests
carrying tools are not resampled because their tools would execute again.
A response that still fails validation fails the block explicitly.
Setting "strict": false keeps the previous lenient fallback, and
streaming responses are unchanged.
Claude-Session: https://claude.ai/code/session_018L7CosQfKB9SGCF8E9fLfY
Copy file name to clipboardExpand all lines: apps/docs/content/docs/workflows/blocks/agent.mdx
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,12 @@ Give the agent a JSON Schema to force structured output. The response is constra
72
72
}
73
73
```
74
74
75
+
The schema is checked after generation.
76
+
A response that fails to parse as JSON, violates the schema (including constraints like `enum`, `minLength`, and number bounds), or was cut off at the output token limit counts as a failed generation.
77
+
A block without tools retries once automatically; a block with tools is not retried, because its tools would run again.
78
+
When no valid response remains, the block fails with the validation error instead of silently returning unstructured text.
79
+
Set `"strict": false` in the response format to skip enforcement and accept whatever the model returns.
80
+
75
81
### Advanced
76
82
77
83
Some settings live under advanced, or appear only for models that support them:
0 commit comments