graphrag
graphrag copied to clipboard
Fix: Replace manual placeholders to avoid .format() issues in COMMUNITY_REPORT_PROMPT
Description
- In the
community_reports_extractorfile Using .format() caused errors because the COMMUNITY_REPORT_PROMPT has other{}braces (e.g., in JSON examples). - Python .format() tries to parse those and fails.
Related Issues
#1900
Proposed Changes
- Switched to using .replace() to manually substitute
{input_text}and{max_report_length}. - Avoids conflict with embedded braces and ensures prompt generation works correctly.
Checklist
- [x] I have tested these changes locally.
- [x] I have reviewed the code changes.
- [ ] I have updated the documentation (if necessary).
- [ ] I have added appropriate unit tests (if applicable).
Additional Notes
- The error occurred because .format() was used on a prompt where only the input variables ({input_text} and {max_report_length}) were meant to be replaced.
- Although all non-input curly braces (for JSON structure) were correctly escaped with double brackets {{ }}, using .format() still caused issues due to complex formatting.
- Replaced .format() with manual .replace() for input_text and max_report_length to fix the problem safely without impacting the rest of the prompt structure.
@AlonsoGuevara Please review the PR when you have time. Thanks!
Did you run prompt tuning? It looks like the issue is that prompt tune calls format to insert its variables, reducing the bracket count by one when written back out. Running with default prompts does not exhibit the issue.
We're going to look for a fix on the prompt tuning side so we can retain the use of format
Yes, I did manual prompt tuning, understood now it makes sense. Thanks