Skip to content

fix(eval): reuse configured grading provider references - #9460

Merged
mldangelo-oai merged 17 commits into
promptfoo:mainfrom
RitwijParmar:codex/geval-litellm-regression
May 27, 2026
Merged

mldangelo-oai merged 17 commits into
promptfoo:mainfrom
RitwijParmar:codex/geval-litellm-regression

Conversation

@RitwijParmar

@RitwijParmar RitwijParmar commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Reuse already-loaded providers referenced by ID or label for runtime model-grader options and assertions after defaults and scenarios are assembled.
  • Resolve provider references nested inside grading type maps such as provider: { text: litellm:grader }, including package-API preprocessing and lower-level evaluator execution.
  • Share provider-map/type-map handling across both paths and ensure a provider label can never shadow another configured provider's ID.
  • Preserve lazy selection in typed grading-provider maps so unused provider alternatives are not constructed or allowed to fail an unrelated assertion type.
  • Preserve object identity for fully resolved typed grader maps; suite env augmentation now clones only when a deferred entry needs it.
  • Reuse configured graders for id-only typed options such as { text: { id: 'litellm:judge' } } while retaining option-bearing inline providers.
  • Resolve typed configured references and deferred suite env in one shared pass, removing duplicate caller-side orchestration.
  • Preserve suite-level environment overrides for deferred inline typed graders, including inherited assertions, and distinguish typed maps from invalid or type-named ProviderOptionsMap entries.
  • Keep the G-Eval LiteLLM request-context and phase-aware empty-output diagnostics from the original patch.
  • Keep the LiteLLM docs focused on the repaired behavior: a configured LiteLLM judge can be referenced by ID while the test restricts execution to the target provider being evaluated.

Why this is needed

The original regression test proved that G-Eval can call a LiteLLM grader, but it did not prove that a configured grader instance was reused. Before this fix, CLI configuration could load a top-level litellm:grader with its proxy settings and then silently construct a different fallback LiteLLM provider when a model-graded assertion referenced that ID.

The red-team follow-up found a second bypass: the supported typed form provider: { text: litellm:grader } was not dereferenced. The eval could still pass while both grading calls went to the fallback endpoint instead of the configured proxy endpoint.

A review follow-up found a third correctness edge case: when one configured provider's label matched a different provider's ID, resolving that ID could silently choose the labelled provider. Provider IDs now take precedence over label aliases in both evaluation paths.

A final adversarial pass found a fourth regression in the typed-map repair: package-API evaluation eagerly constructed every typed provider alternative. A text-only G-Eval could therefore fail on an unused invalid or unconfigured embedding provider. Typed maps now eagerly substitute only already-loaded configured references and defer all other entries until their assertion type is actually selected.

A subsequent Codex review found that the deferred path dropped suite-level env for an inline selected typed grader, which could leave credentials or endpoint templates unresolved. Deferred entries now carry merged suite environment overrides without instantiating unused alternatives.

A subsequent Copilot review found that the type-map discriminator mistook a type-named ProviderOptionsMap entry such as { text: { config: ... } } for a typed grader, even though typed provider options require an id. Typed maps are now recognized only when at least one type key contains a loadable typed provider value.

A final Codex documentation review found that the initial LiteLLM guidance included an incorrect shell-style API-key placeholder. The documentation is now reduced to one provider-ID reuse example and delegates proxy credentials and environment configuration to the canonical LiteLLM provider guide.

A final-head Codex review then found that inline typed graders inherited through defaultTest.assert bypassed suite-env augmentation after default assertions were merged at runtime. The shared deferred-provider helper is now applied after that merge as well, including within assertion sets.

A final-head Copilot review found that { text: '' } was accepted as a typed provider map even though it cannot select a provider. Empty string entries are now rejected by the discriminator, consistent with typed provider options requiring a non-empty id.

A follow-up Copilot review found that suite-env augmentation shallow-cloned typed grader maps even when every nested provider was already resolved and no env injection was possible. The helper now lazily clones only if it modifies a deferred entry, with regressions covering both paths.

A final Copilot review found that the supported id-only typed option form { text: { id: 'litellm:judge' } } still constructed a fresh provider instead of reusing a configured provider with that ID. Id-only typed entries now resolve through the configured map, while entries with config, env, labels, or other options stay inline.

A simplification pass then collapsed configured typed-reference lookup and deferred suite-env augmentation into one non-recursive typed-map pass in the shared helper. This removes the exported env-only helper and duplicate composition in both evaluation entry points without changing the tested routing behavior.

Root cause

Package-API preprocessing and lower evaluator execution did not consistently resolve configured grading-provider references in all supported shapes. String references were repaired first, but references nested under text, embedding, classification, or moderation still bypassed configured provider reuse.

This patch resolves both direct references and typed-map references through a shared loaded-provider map while leaving inline provider configuration intact. The shared map uses ID-first insertion, non-overwriting label aliases, and own-key lookup semantics. A single typed-map substitution pass is shared by both evaluation paths, preserves suite environment overrides for deferred inline entries before and after default assertion merging, does not instantiate unused alternatives, and does not claim option-map or empty-string entries that lack a usable typed provider ID.

Validation

  • npm run f
  • npm run l
  • npm run tsc -- --pretty false
  • SKIP_OG_GENERATION=true npm --prefix site run build
  • npm run build
  • PROMPTFOO_DISABLE_TELEMETRY=true npm test -- test/index.test.ts test/evaluator/assertions.test.ts test/util/gradingProvider.test.ts test/matchers/g-eval.test.ts test/matchers/getGradingProvider.test.ts test/matchers/utils.test.ts test/evaluator/defaultTest.test.ts test/evaluator/gradingConcurrency.test.ts (215 passed)
  • PROMPTFOO_DISABLE_TELEMETRY=true npm test -- test/index.test.ts test/evaluator/assertions.test.ts test/util/gradingProvider.test.ts test/matchers/g-eval.test.ts test/matchers/llm-rubric.test.ts test/matchers/closed-qa.test.ts test/matchers/factuality.test.ts test/matchers/answer-relevance.test.ts test/matchers/context-recall.test.ts test/matchers/context-relevance.test.ts test/matchers/context-faithfulness.test.ts test/matchers/comparison.test.ts test/matchers/search-rubric.test.ts test/matchers/similarity.test.ts test/matchers/classification.test.ts test/matchers/moderation.test.ts test/assertions/llmRubric.test.ts test/assertions/searchRubric.test.ts test/assertions/contextFaithfulness.test.ts test/assertions/contextRecall.test.ts test/assertions/contextRelevance.test.ts test/assertions/moderation.test.ts (339 passed)
  • Regression coverage validates ID-over-label precedence, lazy unused typed-map alternatives, suite-env preservation for deferred inline and inherited graders, resolved-map identity preservation, id-only typed option reuse without swallowing inline overrides, single-pass typed-map resolution, typed-map/options-map discrimination, and rejection of empty typed provider IDs.
  • The shared judge audit now includes an answer-relevance evaluator regression proving configured text and embedding judge references are both reused; the other text-judge paths pass together in the expanded matcher/assertion run.
  • Built package-API probe with an inline typed LiteLLM grader whose endpoint is rendered from suite env, plus an invalid unused embedding alternative: G-Eval passed and both grading requests hit only the suite-configured endpoint while a supplied fallback endpoint received none.
  • Built package-API probe with configured provider: { text: litellm:judge, embedding: unsupported-provider:unused-embedding }: G-Eval passed and both grading requests hit only the configured LiteLLM endpoint.
  • Built package-API probe with an inline typed LiteLLM grader inherited from defaultTest.assert, endpoint rendered from suite env, and an invalid unused embedding alternative: G-Eval passed and both grading requests hit only the suite-configured endpoint.
  • Live CLI dual-endpoint probe for an inline typed LiteLLM grader inherited from defaultTest.assert: exported result passed with two grading requests, and both requests hit only the suite-configured endpoint rather than the forced fallback endpoint.
  • Live CLI dual-endpoint probe for defaultTest.options.provider: { text: litellm:judge }: exported result passed with two grading requests, and both requests hit only the configured endpoint.
  • Live CLI dual-endpoint probe for assertion provider: { text: litellm:judge }: exported result passed with two grading requests, and both requests hit only the configured endpoint.
  • Live CLI dual-endpoint probe for defaultTest.options.provider: { text: { id: litellm:judge } }: exported result passed with two grading requests, and both requests hit only the configured endpoint while the forced fallback endpoint received none.
  • After simplification, live CLI and built package-API dual-endpoint probes for defaultTest.options.provider: { text: { id: litellm:judge } } both passed; each made two grading requests only to the configured endpoint while the forced fallback endpoint received none.
  • After merging current origin/main at 3abc9d010, npm run f, npm run l, npm run tsc -- --pretty false, npm run build, and SKIP_OG_GENERATION=true npm --prefix site run build passed.
  • On the merged head, the expanded model-graded and persisted-secret regression set passed (374 passed), including test/models/evalResult.test.ts to confirm nested grader credentials remain redacted in stored results.
  • On the merged head, live CLI and built package-API dual-endpoint probes for defaultTest.options.provider: { text: { id: litellm:judge } } both passed again; each made two grader requests only to the configured endpoint while the forced fallback endpoint received none.
  • Live CLI through a local LiteLLM proxy: configured direct-reference G-Eval passed with one target proxy call plus two grader proxy calls; exported result reports gradingResult.tokensUsed.numRequests: 2.
  • Live CLI through the same LiteLLM proxy: configured litellm:grader llm-rubric passed with one grading request.
  • Live CLI using inline LiteLLM G-Eval grader configuration passed with two grading requests and no extra target column.
  • Live CLI using a direct OpenAI G-Eval grader passed with two grading requests as a comparison path.

Full-suite note

npm test was attempted twice locally. Under the full parallel run, unrelated localhost server/fetch tests failed with timeouts and EADDRNOTAVAIL port-exhaustion errors. The affected files pass together when rerun directly: test/server/routes/version.route.test.ts, test/server/routes/redteam.test.ts, test/server/routes/media.test.ts, and test/fetch.compression.test.ts (83 passed).

@RitwijParmar
RitwijParmar requested review from a team, ianw-oai and mldangelo-oai as code owners May 26, 2026 15:29

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 All Clear

I reviewed the PR changes affecting G-Eval grading, including updated error messaging for empty outputs, new LiteLLM-based tests, and related documentation. The production code change is limited to clearer failure reasons and does not alter data flows, capabilities, or output handling. No LLM security vulnerabilities were introduced by these changes.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

@mldangelo-oai mldangelo-oai changed the title test: cover G-Eval LiteLLM grader path fix(eval): reuse configured grading provider references May 26, 2026
@mldangelo-oai
mldangelo-oai requested a review from Copilot May 27, 2026 02:52
@mldangelo-oai

Copy link
Copy Markdown
Contributor

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes grading-provider resolution so model-graded assertions (including typed provider: { text: ... } maps) reuse already-loaded provider instances by ID/label instead of silently constructing fallback providers, and improves G-Eval LiteLLM diagnostics when a phase returns no output.

Changes:

  • Reuse configured providers for grading by resolving string and typed-map provider references through the loaded provider map (both during package-API preprocessing and evaluator runtime assembly).
  • Improve G-Eval “no output” failures to include the phase and provider id for easier debugging (notably for LiteLLM graders).
  • Add/adjust regression tests and update docs to clarify LiteLLM grader configuration vs provider-id reuse.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/matchers/g-eval.test.ts Adds coverage for LiteLLM context propagation across both G-Eval phases and phase-aware empty-output diagnostics.
test/index.test.ts Expands provider resolution tests to cover typed grading provider maps and adjusts fallback cases.
test/evaluator/assertions.test.ts Adds evaluator-level regression coverage ensuring configured graders are reused (including inside assert-sets).
src/matchers/llmGrading.ts Improves “no output” errors to include G-Eval phase and provider id.
src/evaluator.ts Resolves configured provider references (including typed maps and nested assert-sets) after defaults/scenarios are merged.
src/evaluate.ts Resolves typed grading provider maps during runtime test-suite construction so configured providers can be reused.
site/docs/configuration/expected-outputs/model-graded/g-eval.md Documents LiteLLM grader setup and explains provider-id reuse vs inline grader-only configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/index.test.ts Resolved
Comment thread test/index.test.ts Resolved

@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: d25dcfeed8

ℹ️ 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/evaluator.ts Resolved
…sion

Extracts the duplicated GRADING_PROVIDER_TYPE_KEYS, isProviderTypeMap,
and provider-map builder out of src/evaluate.ts and src/evaluator.ts
into src/util/gradingProvider.ts so both layers stay in sync.

The shared buildConfiguredProviderMap now adds provider ids in a first
pass and only fills label aliases that have not been claimed by an id,
preventing a labelled provider from silently shadowing another
provider's id lookup. Also switches the runtime resolver's
'id' in provider check to Object.hasOwn for symmetry with the
providerMap lookup and to avoid prototype-chain false positives.

Adds unit coverage for the shared helper and end-to-end regressions
for the id/label collision case in both the package and runtime
resolution paths.
@mldangelo

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@promptfoo-scanner

@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: cfcbbe3cde

ℹ️ 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/evaluate.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/util/gradingProvider.ts Resolved
@mldangelo-oai

Copy link
Copy Markdown
Contributor

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@promptfoo-scanner

@mldangelo-oai
mldangelo-oai requested a review from Copilot May 27, 2026 06:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/util/gradingProvider.ts Resolved
@mldangelo-oai

Copy link
Copy Markdown
Contributor

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@promptfoo-scanner

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ 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".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@mldangelo-oai
mldangelo-oai requested a review from Copilot May 27, 2026 11:14
@mldangelo-oai

Copy link
Copy Markdown
Contributor

@promptfoo-scanner

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ 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".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@promptfoo-scanner

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ 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".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@mldangelo-oai

Copy link
Copy Markdown
Contributor

@promptfoo-scanner Please rescan the current head; the prior external check has remained in progress without output after all CI checks passed.

@mldangelo-oai
mldangelo-oai merged commit 28b26d9 into promptfoo:main May 27, 2026
32 of 33 checks passed
@mldangelo-oai

Copy link
Copy Markdown
Contributor

Thank you!

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.

4 participants