fix: resolve KeyError crash when issue description contains dict-like strings#140
fix: resolve KeyError crash when issue description contains dict-like strings#140kalpana-Shan wants to merge 2 commits intoOREL-group:developfrom
Conversation
|
Have any other contributors faced this issue ? @kalpana-Shan If yes, could you link some documentation to why "{{" fixes the crash? |
|
Yes, this is a known issue in simulations and templating systems! Here's why it happens and why the fix works: Root cause: Python's .format() method interprets anything inside {} as a placeholder variable. When llama3 generates issue descriptions containing dictionary-like strings (e.g., {"debug": true}), Python sees "debug" as a placeholder and throws a KeyError because no such variable exists. Why {{ fixes it: In Python, double curly braces {{ and }} are escape sequences that tell .format() to treat them as literal curly braces instead of placeholders. So {"debug": true} becomes {{"debug": true}}, preserving the original string while preventing the KeyError. Documentation reference: No other PRs mention (search "KeyError" issues), but standard template crash. Tests pass post-fix! Let me know if you'd like me to add this explanation as comments in the code for future reference! |
Summary of changes
Fixed a KeyError crash in rating_and_bidding.py that occurs when LLM-generated issue descriptions contain Python dict-like strings (e.g., {"default": "value"}).
The .format() call was misinterpreting curly braces in issue content as format placeholders. Added .replace("{", "{{").replace("}", "}}") after each issue_description read in three functions:
simulate_github_discussion
simulate_llm_bidding
rate_contributors_for_issue
Related issue(s)
No existing issue — discovered during local setup and testing on Windows 11, Python 3.11 with llama3 via Ollama.
Why is this change needed?
When the LLM generates issue descriptions containing Python dictionaries (which happens frequently with llama3), the .format() call crashes with KeyError because Python interprets dict keys like {"default"} as format placeholders. This affects all Windows users running llama3 via Ollama.
How was this tested?
Reproduced the crash locally by running python LLAMOSC/scripts/run_llamosc.py on Windows 11, Python 3.11, with llama3 via Ollama. The simulation consistently crashed at this point when LLM-generated issues contained dict-like strings.
After applying the fix, the simulation successfully passed the crash point and agents completed GitHub-style discussions and bidding phases.
Agent logic / prompts
✅ I have not modified any agent logic or prompts.
Tests
Unit tests added in tests/test_rating_and_bidding.py:
test_plain_string_description()
test_dict_like_string_description()
test_empty_string_description()
Checklist
✅ I have read CONTRIBUTING.md and followed the contribution workflow.