Skip to content

eval_prompts() parses a backticked prompt: mention in a doc comment as a scenario prompt #2237

Closed

Description

@malibio

Summary

eval_prompts() (in packages/agent/src/agent_guidance.rs, used by guidance_is_not_contaminated_by_eval_prompts) treats a prompt: occurrence inside a doc comment as a real scenario prompt, because its "is this an object key?" check does not exclude a preceding backtick.

Cause

agent_guidance.rs:309-314 rejects a match whose preceding character is alphanumeric, _, or .:

// Only treat this as an object key. `prompt:` also appears inside
// identifiers/field access (e.g. `fixture.prompt:`) and prose.
if source[..idx].chars().next_back()
    .is_some_and(|c| c.is_alphanumeric() || c == '_' || c == '.')

A backtick is none of those. So the fixture's own header comment — which legitimately discusses the guard by naming the thing it parses:

* `guidance_is_not_contaminated_by_eval_prompts` enforces it by parsing the
* `prompt:` literals out of this file: …

matches, and the parser then reads from the closing backtick to the next " it finds, capturing a large span of comment prose and source as a single "prompt".

Impact

Low, and the guard is not made vacuous — verified empirically:

  • Site accounting still balances (21 sites / 21 parsed), so the prompts.len() == sites fail-open assertion still holds.
  • The phantom span clears the 4-word threshold, so it does not produce a false positive today.

But it is a latent false-positive source: the captured span is arbitrary file text, so ordinary prose in a comment could collide with guidance wording and fail the guard for a reason having nothing to do with any scenario prompt. It also inflates the reported site count, which is confusing when auditing the guard by hand — this cost real time during #1977, where the 21st site had to be explained before the 20 real prompts could be trusted.

Fix

Add the backtick (and plausibly '/") to the excluded preceding characters, so a prompt: inside inline code or a quoted mention is not treated as an object key. Pin it with a case in eval_prompt_parser_handles_backticks_and_escapes, which already covers the parser's other literal shapes.

Worth doing in the parser rather than by rewording the fixture's comment: the comment is accurate and useful, and dodging a parser quirk by editing prose treats the symptom.

Found by

The re-review on PR #2232 (#1977), as a 🟢 suggestion. Deferred there because the fix belongs in the guard, not in the eval fixture that tripped it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions