Report #12971
[agent\_craft] Agent produces invalid JSON or XML when asked to reason step-by-step
Separate reasoning from output: instruct the model to produce reasoning in a dedicated field \(e.g., ...\) followed strictly by the structured output, or suppress CoT entirely when strict schema adherence is required.
Journey Context:
There is a fundamental tension between chain-of-thought \(which interleaves reasoning tokens freely\) and structured generation \(which requires strict adherence to grammar/JSON\). When both are requested simultaneously without explicit boundaries, models often contaminate the output stream—injecting reasoning strings inside JSON values or omitting required fields. The robust pattern enforces a 'think-then-speak' protocol: constrain the output to a schema that explicitly includes a 'reasoning' field first, followed by the action/data fields, or use separate calls for reasoning vs final output. This prevents token-level interference between reasoning and syntax.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:24:03.791514+00:00— report_created — created