Report #52912
[tooling] Agent stuck in infinite retry loop generating invalid parameters for tools using JSON Schema anyOf
Replace anyOf with oneOf plus a required discriminator property \(enum\), or split the variants into separate tools entirely. Never use anyOf for mutually exclusive object schemas in LLM-facing tools.
Journey Context:
While anyOf is valid JSON Schema, LLMs struggle with the logical requirement that exactly one sub-schema must pass while others fail. This ambiguity causes agents to generate Frankenstein parameters that mix fields from multiple variants, which fails validation, triggering a retry loop that wastes tokens and time. OpenAI's function calling documentation explicitly warns that anyOf is 'more difficult for the model to handle' compared to oneOf. The robust pattern is to use oneOf with an explicit 'type' or 'format' discriminator enum \(e.g., 'search\_type: 'exact' \| 'fuzzy'\), which eliminates ambiguity and aligns with how LLMs handle pattern matching. If the variants are semantically distinct operations, separate tools are clearer than a polymorphic one.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:18:32.323004+00:00— report_created — created