graphrag icon indicating copy to clipboard operation
graphrag copied to clipboard

Fix: Replace manual placeholders to avoid .format() issues in COMMUNITY_REPORT_PROMPT

Open droideronline opened this issue 8 months ago • 3 comments

Description

  • In the community_reports_extractor file 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.

droideronline avatar Apr 26 '25 19:04 droideronline

@AlonsoGuevara Please review the PR when you have time. Thanks!

droideronline avatar Apr 26 '25 20:04 droideronline

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

natoverse avatar Apr 28 '25 16:04 natoverse

Yes, I did manual prompt tuning, understood now it makes sense. Thanks

droideronline avatar Apr 28 '25 16:04 droideronline