Report #4169
[agent\_craft] Agent generates malformed JSON or hallucinates tool parameters when using system prompt instructions
Use native 'function calling'/'tools' API instead of prompting for JSON. If forced to use base models, use 'JSON mode' with response\_format=\{'type': 'json\_object'\} rather than regex parsing.
Journey Context:
Many developers implement tool use by writing 'You must output JSON like \{"action": ...\}' in the system prompt. This is brittle: models may output markdown fences, truncate JSON, or hallucinate schemas. The breakthrough was OpenAI's 'function calling' fine-tuning \(and later 'tools' API\), where the model is explicitly trained on tool schemas. This reduces hallucination by an order of magnitude and enforces schema compliance. If using open-weight models without native tool support, 'JSON mode' \(constrained decoding\) is superior to prompt engineering because it guarantees valid JSON syntax at the token level.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:56:28.671400+00:00— report_created — created