graphrag icon indicating copy to clipboard operation
graphrag copied to clipboard

[Bug]: stray double quote is embedded in every DRIFT primer prompt

Open simpleqt opened this issue 3 months ago • 2 comments

DriftPrimer.build_prompt (packages/graphrag/graphrag/query/structured_search/drift_search/primer.py, lines 83-86 at v3.1.2) builds the query-expansion prompt with a triple-quoted f-string that ends with {template}\n" — so a literal " is sent to the LLM as part of every DRIFT primer prompt, immediately after the (long) community-report template:

        prompt = f"""Create a hypothetical answer to the following query: {query}\n\n
                  Format it to follow the structure of the template below:\n\n
                  {template}\n"
                  Ensure that the hypothetical answer does not reference new named entities that are not present in the original query."""

The stray " sits at the end of the {template}\n line (third line of the f-string).

Steps to reproduce

  1. Index a dataset and run any DRIFT search query.
  2. Inspect the primer prompt built by DriftPrimer.build_prompt (log it or step through with a debugger).
  3. The prompt contains a stray " right after the community report template, before Ensure that the hypothetical answer....

Expected behavior

No stray double quote in the prompt. The fix is a one-character deletion. A fix branch is available at https://github.com/simpleqt/graphrag/tree/fix-drift-primer-stray-quote (opening PRs appears limited to collaborators, hence filing as an issue).

  • GraphRAG Version: v3.1.2 (main @ 6dad6d2)
  • OS/Python: any

simpleqt avatar Aug 23 '26 10:08 simpleqt

Independently verified against main (6dad6d2): PrimerQueryProcessor.expand_query captures a prompt ending TEMPLATE-CONTENT\n"\n Ensure that ... — the stray " from the f-string line {template}\n" reaches every primer prompt exactly as reported.

I also have a one-character fix plus a regression test ready on my fork (weike-zhang/graphrag@fix/drift-primer-stray-quote — test fails before, passes after). I attempted to open a PR but GitHub reports that PR creation on this repository is currently restricted, matching what @simpleqt observed — so leaving this here for whoever picks it up.

weike-zhang avatar Aug 24 '26 15:08 weike-zhang

Thanks @weike-zhang for the independent verification and for preparing the fix + regression test. I hit the same restriction you did — and --draft creation is blocked too (the open-PR-count limit exempts drafts, so this looks like a repo-wide pause on outside PR creation rather than a per-user quota).

To make this zero-effort for whoever has write access, I've folded your regression test (with credit) on top of the identical one-character fix on my fork: https://github.com/simpleqt/graphrag/tree/fix-drift-primer-stray-quote (commits 0129fdd + 49e625d, based on 6dad6d2). Verified locally: the test fails on main and passes with the fix.

Either your branch or mine can be picked up as-is; they differ only in commit message wording.

simpleqt avatar Aug 24 '26 15:08 simpleqt