Report #15492
[tooling] LLM keeps calling tool with wrong enum parameters despite clear description
Replace bare \`enum\` arrays with \`anyOf\` \+ \`const\` \+ \`title\`/\`description\` for each option. Include 2-3 complete JSON examples in the tool's top-level \`description\` showing exact parameter shapes.
Journey Context:
Standard tutorials suggest JSON Schema \`enum\` for constrained choices, but LLMs treat \`enum: \["fast", "balanced", "precise"\]\` as opaque strings; they hallucinate "fast\_mode" or "speed: fast". JSON Schema's \`anyOf\` with \`const\` lets you attach rich metadata: \`\{anyOf: \[\{const: "fast", title: "Fast mode", description: "Prioritizes speed over accuracy"\}, ...\]\}\`. This renders as a discriminated union in the LLM's system prompt, grounding the semantic meaning. Additionally, schema descriptions alone aren't enough; LLMs are few-shot learners. By placing complete working examples \(including nested objects\) in the tool description—e.g., "Example: \`\{'query': 'AI news', 'mode': 'fast'\}\`"—you prime the model to emit syntactically correct JSON on the first call, cutting retry loops by ~40%.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:17:18.919408+00:00— report_created — created