Repository navigation
fix(eval): reuse configured grading provider references - #9460
Conversation
There was a problem hiding this comment.
👍 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
|
@codex review |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
…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.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
@promptfoo-scanner |
There was a problem hiding this comment.
💡 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".
|
@codex review |
|
@promptfoo-scanner |
|
@codex review |
|
@promptfoo-scanner |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@promptfoo-scanner |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
@promptfoo-scanner |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@promptfoo-scanner Please rescan the current head; the prior external check has remained in progress without output after all CI checks passed. |
|
Thank you! |
Summary
provider: { text: litellm:grader }, including package-API preprocessing and lower-level evaluator execution.{ text: { id: 'litellm:judge' } }while retaining option-bearing inline providers.ProviderOptionsMapentries.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:graderwith 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
embeddingprovider. 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
envfor 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
ProviderOptionsMapentry such as{ text: { config: ... } }for a typed grader, even though typed provider options require anid. 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.assertbypassed 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-emptyid.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 withconfig,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, ormoderationstill 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 fnpm run lnpm run tsc -- --pretty falseSKIP_OG_GENERATION=true npm --prefix site run buildnpm run buildPROMPTFOO_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)answer-relevanceevaluator regression proving configuredtextandembeddingjudge references are both reused; the other text-judge paths pass together in the expanded matcher/assertion run.env, plus an invalid unusedembeddingalternative: G-Eval passed and both grading requests hit only the suite-configured endpoint while a supplied fallback endpoint received none.provider: { text: litellm:judge, embedding: unsupported-provider:unused-embedding }: G-Eval passed and both grading requests hit only the configured LiteLLM endpoint.defaultTest.assert, endpoint rendered from suiteenv, and an invalid unusedembeddingalternative: G-Eval passed and both grading requests hit only the suite-configured endpoint.defaultTest.assert: exported result passed with two grading requests, and both requests hit only the suite-configured endpoint rather than the forced fallback endpoint.defaultTest.options.provider: { text: litellm:judge }: exported result passed with two grading requests, and both requests hit only the configured endpoint.provider: { text: litellm:judge }: exported result passed with two grading requests, and both requests hit only the configured endpoint.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.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.origin/mainat3abc9d010,npm run f,npm run l,npm run tsc -- --pretty false,npm run build, andSKIP_OG_GENERATION=true npm --prefix site run buildpassed.374 passed), includingtest/models/evalResult.test.tsto confirm nested grader credentials remain redacted in stored results.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.gradingResult.tokensUsed.numRequests: 2.litellm:graderllm-rubricpassed with one grading request.Full-suite note
npm testwas attempted twice locally. Under the full parallel run, unrelated localhost server/fetch tests failed with timeouts andEADDRNOTAVAILport-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, andtest/fetch.compression.test.ts(83 passed).