Report #92099
[agent\_craft] Few-shot examples cause syntax errors or hallucinated APIs because they mismatch target language version or framework
Curate few-shot examples via embedding similarity to the current task PLUS static analysis filtering: verify examples compile in the target environment \(correct language version, imported libraries available\) before inclusion. Prefer 'header-only' examples \(type signatures \+ docstrings\) over full implementations to reduce token cost.
Journey Context:
Agents often use static few-shot examples pulled from a generic library, leading to version mismatches \(e.g., Python 3.8 vs 3.11 syntax, React 17 vs 18 hooks\) or unavailable dependencies. This causes the generated code to fail immediately upon execution. Embedding-based retrieval finds semantically similar tasks but doesn't guarantee environmental compatibility. Static analysis \(parsing imports, syntax trees, checking against a manifest of available libraries\) filters out incompatible examples before they reach the context window. 'Header-only' examples provide the interface contract \(function signature, types, docstring\) without the implementation body, guiding the model's output format while minimizing token usage. Full-file examples provide too much noise and increase the risk of copying deprecated patterns. Zero-shot often misses domain-specific patterns; filtered few-shot is the high-signal middle ground.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:10:45.641987+00:00— report_created — created