Skip to content

feat(config): add YAML source location to prompt reference errors#9940

Merged
mldangelo merged 4 commits into
promptfoo:mainfrom
JustasMonkev:feat/prompt-ref-error-yaml-location
Jul 3, 2026
Merged

feat(config): add YAML source location to prompt reference errors#9940
mldangelo merged 4 commits into
promptfoo:mainfrom
JustasMonkev:feat/prompt-ref-error-yaml-location

Conversation

@JustasMonkev

Copy link
Copy Markdown
Contributor

Summary

Prompt reference validation errors now point at the offending line in the configuration file.

Before

> Test #1 ("Missing prompt") references prompt "Missing Prompt" which does not exist.

(Use `node --trace-warnings ...` to show where the warning was created)

file://text-to-sql-ts/node_modules/promptfoo/dist/src/main.js:1761
                        throw new PromptReferenceValidationError(
                              `Test #${testIdx + 1}${testDesc} references prompt "${ref}" which does not exist.\nAvailable prompts: [${available.join(", ")}]`
                        );
                              ^

PromptReferenceValidationError: Test #1 ("CoT prompt includes thinking tag") references prompt "Chain of Thought & Few-Shot Examples" which does not exist.
Available prompts: [Basic]

After

> promptfooconfig.yaml:9:9: Test #1 ("Missing prompt") references prompt "Missing Prompt" which does not exist.

$ promptfoo eval -c promptfooconfig.yaml --output data/results.csv

(node:62047) ExperimentalWarning: DecompressInterceptor is experimental and subject to change
(Use `node --trace-warnings ...` to show where the warning was created)

file:///promptfoo_promptfoo/src/util/validateTestPromptReferences.ts:162
      throw new PromptReferenceValidationError(location ? `${location}: ${message}` : message);
            ^

PromptReferenceValidationError: text-to-sql-ts/promptfooconfig.yaml:35:9: Test #1 ("CoT prompt includes thinking tag") references prompt "Chain of Thought & Few-Shot Examples" which does not exist.
Available prompts: [Basic]

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.60440% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.46%. Comparing base (9a337ab) to head (7020b8b).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9940      +/-   ##
==========================================
+ Coverage   79.42%   79.46%   +0.03%     
==========================================
  Files         922      924       +2     
  Lines       74008    74130     +122     
  Branches    23821    23861      +40     
==========================================
+ Hits        58784    58905     +121     
- Misses      15224    15225       +1     
Flag Coverage Δ
backend 81.33% <95.60%> (+0.02%) ⬆️
site 4.58% <ø> (+0.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68b257b2d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/util/validateTestPromptReferences.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0008b8c4f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/util/config/load.ts
testSuite.tests || [],
testSuite.prompts,
typeof testSuite.defaultTest === 'object' ? testSuite.defaultTest : undefined,
{ promptReferenceSources },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid using config locations for CLI-supplied tests

When --tests/--vars overrides the config tests, parsedTests comes from the CLI path (config.tests is set from cmdObj.tests || cmdObj.vars), but the validator is still given only promptReferenceSources from the config files. If the ignored config file happens to contain the same missing prompt name, the new error prefix points at that unused config line instead of the test file actually being validated, which sends users to edit the wrong source.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65db3da327

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +46 to +47
const column = line.indexOf(ref);
return column === -1 ? undefined : `${source.path}:${lineNumber}:${column + 1}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid substring matches for prompt locations

When the missing prompt name is a substring of an earlier prompt reference in the same prompts block, this raw indexOf returns the earlier line and item.location ??= keeps it. For example, if a test lists Basic Assistant before missing Basic, and only Basic Assistant exists, the error for Basic points at the valid Basic Assistant entry instead of the bad line; the lookup should match the YAML list value rather than any substring on the line.

Useful? React with 👍 / 👎.

…ator

A missing prompt whose name is a substring of a valid prompt referenced
earlier in the same prompts block (e.g. 'Ghost' vs '- GhostBuster') was
located via a raw indexOf, so the error pointed at the valid prompt's
line. Prefer a list item whose whole value equals the ref, falling back
to a substring match only when there's no exact match (keeps flow-style
'prompts: [ref]' working).
@mldangelo

Copy link
Copy Markdown
Member

Reviewed and QA'd this thoroughly — the location hints are a genuinely nice DX win, and I verified the hand-rolled locator holds up well on real configs (via actual promptfoo eval runs, not just unit mocks):

  • block styleconfig.yaml:9:9
  • flow style (prompts: ['Missing']) → config.yaml:8:16 ✓ (points inside the flow list)
  • comment before the ref → correctly skips the comment line ✓
  • ref string also in vars → correctly points at the prompts: line, not the vars line ✓
  • multiple -c config files → attributes to the right file ✓

On the three Codex P2s: #1 (ref-in-vars stealing the location) is already handled by the prompts:-block restriction, and #2 (CLI-supplied --tests) degrades gracefully to no location. But #3 (substring match) was real — I reproduced it: a valid prompt GhostBuster referenced above a missing Ghost in the same block made the error point at GhostBuster's line, since refLocation used a raw indexOf.

I pushed a small fix (7020b8b1d8): the locator now prefers a list item whose whole value equals the ref, falling back to a substring match only when there's no exact one — so flow-style (prompts: [ref]) still resolves. Added a regression test for the substring case. 175 tests pass, tsc + Biome clean.

Leaving the merge to you since I added to it — ready once CI is green.

@mldangelo

Copy link
Copy Markdown
Member

Thank you!

@mldangelo mldangelo merged commit 5f13e76 into promptfoo:main Jul 3, 2026
33 checks passed
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