-
Notifications
You must be signed in to change notification settings - Fork 17
fix(evaluator): fall back when a judge backend rejects structured output #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcusds
wants to merge
7
commits into
main
Choose a base branch
from
evaluator-judge-structured-output-fallback/mschwab
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3dac3d
fix(evaluator): fall back when a judge backend rejects structured output
marcusds e164722
Merge remote-tracking branch 'origin/main' into evaluator-judge-struc…
marcusds ef45a2c
fix(evaluator): recover concurrent structured-output requests
marcusds 3732118
fix(evaluator): tighten structured-output rejection handling
marcusds c486e97
fix(evaluator): detect param-agnostic structured-output rejections
marcusds c8a2b82
fix(evaluator): downgrade structured output per rendered request
marcusds 19c6da1
Merge branch 'main' into evaluator-judge-structured-output-fallback/m…
marcusds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import json | ||
| from collections.abc import Collection | ||
| from enum import Enum | ||
|
|
||
| from jsonschema.exceptions import SchemaError | ||
|
|
@@ -106,18 +107,46 @@ def default_structured_output_mode(format: str) -> StructuredOutputMode: | |
| raise ValueError(f"Unsupported structured output format: {format}") | ||
|
|
||
|
|
||
| def _looks_like_unsupported_guided_json_error(message: str) -> bool: | ||
| _STRUCTURED_OUTPUT_PARAMS = ("guided_json", "nvext", "extra_body", "response_format") | ||
|
|
||
|
|
||
| def _rejected_field_text(lowered_message: str) -> str: | ||
| """Drop the trailing list of accepted fields so only the rejected one is matched.""" | ||
| return lowered_message.split("expected one of", 1)[0] | ||
|
|
||
|
|
||
| def looks_like_unsupported_structured_output_error(message: str) -> bool: | ||
| """Whether *message* reads as a backend rejecting a structured-output parameter.""" | ||
| lowered = message.lower() | ||
| signatures = ( | ||
| "guided_json is unsupported", | ||
| "unexpected keyword argument 'guided_json'", | ||
| "unexpected keyword argument 'nvext'", | ||
| "is unsupported", | ||
| "is not supported", | ||
| "unexpected keyword argument", | ||
| "extra_forbidden", | ||
| "extra inputs are not permitted", | ||
| "unknown field", | ||
| ) | ||
| if any(sig in lowered for sig in signatures): | ||
| return "guided_json" in lowered or "nvext" in lowered or "extra_body" in lowered | ||
| return False | ||
| if not any(sig in lowered for sig in signatures): | ||
| return False | ||
| rejected = _rejected_field_text(lowered) | ||
| return any(param in rejected for param in _STRUCTURED_OUTPUT_PARAMS) | ||
|
|
||
|
|
||
| def next_structured_output_mode( | ||
| current: StructuredOutputMode, | ||
| message: str, | ||
| rejected_modes: Collection[StructuredOutputMode], | ||
| ) -> StructuredOutputMode: | ||
| """Mode to try after *current* was rejected, ending at prompt-level JSON instruction.""" | ||
| rejected = _rejected_field_text(message.lower()) | ||
| if ( | ||
| current == StructuredOutputMode.NVEXT_GUIDED_JSON | ||
| and StructuredOutputMode.ROOT_GUIDED_JSON not in rejected_modes | ||
| and "nvext" in rejected | ||
| and "guided_json" not in rejected | ||
| ): | ||
| return StructuredOutputMode.ROOT_GUIDED_JSON | ||
| return StructuredOutputMode.UNSUPPORTED | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Marcus, i am wondering, is right way to expose a parameter that specify weather to try with root or with nvext? rather than dyamically trying. |
||
|
|
||
|
|
||
| def _extract_chat_content(response: dict) -> str | None: | ||
|
|
@@ -176,7 +205,7 @@ async def detect_structured_output_mode( | |
| if content and _is_probe_valid_json(content, probe_schema): | ||
| return mode | ||
| except Exception as e: | ||
| if _looks_like_unsupported_guided_json_error(str(e)): | ||
| if looks_like_unsupported_structured_output_error(str(e)): | ||
| continue | ||
| # Probe failures should not abort evaluation startup. If no mode works, | ||
| # caller will fall back to prompt-level strict JSON instruction. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.