Codex keeps hallucinating functions that don’t exist in my codebase — how to reduce this? #7385
-
|
Codex is generating suggestions that refer to fictional helper functions or classes. These functions look plausible but don’t exist anywhere in my project. Context window is enough (approx 2k tokens), and I include the full file before asking the question. How can I force Codex to stay grounded only in the provided code? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hallucinations happen when the model fills in “expected” patterns.
This eliminates most non-existent symbol references. |
Beta Was this translation helpful? Give feedback.
Hallucinations happen when the model fills in “expected” patterns.
To avoid this:
Add this instruction:
“Only reference symbols that appear in the provided code. If unsure, say ‘not found.’”
Wrap code in XML tags:
Use
temperature = 0Use short, direct instructions instead of open-ended ones
If needed, chunk the code into smaller context windows
This eliminates most non-existent symbol references.