Skip to content

Fix #89: Escape curly braces in context before str.format() in synthesis#152

Merged
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
fazalpsinfo-cmyk:fix-89-curly-braces-synthesis
Jul 15, 2026
Merged

Fix #89: Escape curly braces in context before str.format() in synthesis#152
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
fazalpsinfo-cmyk:fix-89-curly-braces-synthesis

Conversation

@fazalpsinfo-cmyk

Copy link
Copy Markdown

Description

Fixes #89 - both question_gen.py and adversarial.py use str.format() to inject document context into prompt templates. If the context contains { or } characters (common in code snippets, JSON, markdown tables, template strings), Python's str.format() interprets them as format placeholders and raises a KeyError.

This makes the synthesis module crash on any real-world corpus that contains structured text with curly braces.

Changes

  • Wrapped context text with .replace("{", "{{").replace("}", "}}") before passing to .format() in:
    • synthesis/question_gen.py (standard question generation)
    • synthesis/adversarial.py (all 5 adversarial types)

Related

Fixes #89


Support open-source contributions: https://buymeacoffee.com/muhamedfazalps

@himanshu231204 himanshu231204 merged commit 6fd12b5 into OpenAgentHQ:main Jul 15, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Congratulations @fazalpsinfo-cmyk!

Your pull request has been successfully merged into main. 🚀

Thank you for contributing to OpenAgentHQ and helping improve the project.

We truly appreciate your contribution and hope to see you back with more amazing PRs!

Happy Open Sourcing! ❤️

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.

synthesis(question_gen/adversarial): prompt template crashes when context contains curly braces (str.format KeyError)

2 participants