Skip to content

fix: resolve KeyError crash when issue description contains dict-like strings#140

Open
kalpana-Shan wants to merge 2 commits intoOREL-group:developfrom
kalpana-Shan:fix/keyerror-clean
Open

fix: resolve KeyError crash when issue description contains dict-like strings#140
kalpana-Shan wants to merge 2 commits intoOREL-group:developfrom
kalpana-Shan:fix/keyerror-clean

Conversation

@kalpana-Shan
Copy link
Copy Markdown

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.

@sarrah-basta
Copy link
Copy Markdown
Contributor

Have any other contributors faced this issue ? @kalpana-Shan

If yes, could you link some documentation to why "{{" fixes the crash?

@kalpana-Shan
Copy link
Copy Markdown
Author

@sarrah-basta

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:
Python string formatting: https://docs.python.org/3/library/string.html#format-string-syntax (escape {{ }})
StackOverflow 100k+ views: https://stackoverflow.com/questions/5466451/how-do-i-escape-curly-brace-characters

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants