Skip to content

fix(graders): insert untrusted code verbatim in judge prompt#97

Merged
frederikprijck merged 1 commit into
mainfrom
fix/judge-prompt-dollar-substitution
Jul 10, 2026
Merged

fix(graders): insert untrusted code verbatim in judge prompt#97
frederikprijck merged 1 commit into
mainfrom
fix/judge-prompt-dollar-substitution

Conversation

@frederikprijck

@frederikprijck frederikprijck commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary

The LLM judge built its user prompt with String.prototype.replace('{code}', code) using a string replacement. String replacements interpret $&, $`, $', and $1..$n as special substitution patterns. Since code is untrusted agent output, any such sequence in the generated code would silently corrupt the judge prompt (e.g. $& expands to the matched {code} placeholder rather than being inserted literally).

This switches both {question} and {code} interpolations to function replacers (() => value), which insert the value verbatim with no pattern interpretation.

Changes

  • packages/eval-core/src/graders/llm-judge.ts — use function replacers so question/code are inserted verbatim.
  • packages/eval-core/tests/graders/engine.test.ts — regression test asserting code containing $&, $1, $`, and $' reaches the judge prompt unmodified.

Test plan

  • npm test (eval-core grader tests, including the new regression test)

Summary by CodeRabbit

  • Bug Fixes

    • Improved prompt construction to safely include user-provided question and code text without accidental text substitution.
    • Prevented special $-style sequences from being altered when generating judge prompts.
  • Tests

    • Added a regression test to verify the full code snippet and question are preserved exactly in the request payload.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@frederikprijck, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 70ed3f09-48fd-496d-bf67-16fbc951b547

📥 Commits

Reviewing files that changed from the base of the PR and between eddd654 and c34a751.

📒 Files selected for processing (2)
  • packages/eval-core/src/graders/llm-judge.ts
  • packages/eval-core/tests/graders/engine.test.ts
📝 Walkthrough

Walkthrough

The change modifies llmJudge's prompt construction to use String.replace function replacers instead of direct string substitution when inserting untrusted question/code into the template, preventing special $-pattern corruption. A regression test verifies verbatim insertion of tricky $-sequences.

Changes

LLM Judge Prompt Safety

Layer / File(s) Summary
Safe template substitution and regression test
packages/eval-core/src/graders/llm-judge.ts, packages/eval-core/tests/graders/engine.test.ts
Prompt building now uses function replacers for {question}/{code} to avoid $-pattern corruption, and a new test confirms tricky $&, $1, $\``, $'` sequences in code are inserted verbatim into the request.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: inserting untrusted code verbatim in the judge prompt.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/judge-prompt-dollar-substitution

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

String.prototype.replace with a string pattern interprets $&, $`, $',
and $1 in the replacement specially. Since the judged code is untrusted
agent output, those sequences silently corrupted the judge prompt (e.g.
$& expanded to the matched {code} placeholder). Use function replacers so
question/code are inserted verbatim.
@frederikprijck frederikprijck force-pushed the fix/judge-prompt-dollar-substitution branch from eddd654 to c34a751 Compare July 9, 2026 14:15
@frederikprijck frederikprijck merged commit a30ae19 into main Jul 10, 2026
6 checks passed
@frederikprijck frederikprijck deleted the fix/judge-prompt-dollar-substitution branch July 10, 2026 08:11
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