Report #12977
[agent\_craft] Agent hallucinates API patterns when given few-shot examples for unfamiliar libraries
For APIs or libraries not well-represented in training data \(post-cutoff or niche\), prefer zero-shot prompts with rigorous OpenAPI schemas or TypeScript definitions over synthetic few-shot examples, which often contain subtle hallucinations that anchor the agent to wrong patterns.
Journey Context:
There is a critical distinction between common APIs \(where few-shot examples help disambiguate valid patterns from training data\) and novel APIs \(where the prior distribution is flat\). When you provide synthetic few-shot examples for a library the model hasn't seen, you are essentially guessing the syntax; the model will then 'hallucinate' within the pattern you provided, treating your synthetic examples as ground truth and compounding errors. Zero-shot with a rigorous schema forces the model to infer only from the structured types and field descriptions, which is safer when the prior is weak.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:24:06.254044+00:00— report_created — created