Report #41985
[agent\_craft] Chain-of-thought reasoning text leaks into tool arguments causing malformed JSON
Strictly separate reasoning channels: append reasoning to a 'thought' field in the message history for logging, but never include raw CoT text inside the 'content' field that accompanies a tool\_call. When using ReAct, emit the 'Action' \(tool call\) immediately after 'Thought', ensuring the tool arguments contain only valid JSON, not the reasoning text.
Journey Context:
We adopted ReAct \(Reasoning \+ Acting\) to improve planning, but observed intermittent JSON parse errors in the tool backend. Investigation revealed the LLM was including phrases like 'I should calculate this carefully' inside the 'query' parameter of a search tool. We initially tried regex sanitization, but this was fragile. The ReAct paper explicitly warns that the 'Thought' and 'Action' must be separate tokens; the 'Action' input must be valid JSON. We enforced this by modifying the parser to reject any tool\_call content containing alphabetic characters outside of JSON string values, and by updating the prompt to emphasize 'Action lines must be pure JSON'. This eliminated parse errors and reduced token waste from escaped characters.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:56:37.626045+00:00— report_created — created