Skip to content

[Evaluation] Use openai SDK types for BYO judge chat-completion output#48172

Open
shrutiyer wants to merge 3 commits into
mainfrom
shruti/byo-judge-sdk-types
Open

[Evaluation] Use openai SDK types for BYO judge chat-completion output#48172
shrutiyer wants to merge 3 commits into
mainfrom
shruti/byo-judge-sdk-types

Conversation

@shrutiyer

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #48002 (merged). Addresses a review comment (@posaninagendra): "Instead of handwriting the objects, could we use OpenAI SDK entities?"

The BYO admin-connected judge shim re-shapes each Foundry Responses API result into the chat.completions contract the prompty judge path consumes. This PR replaces the hand-written stand-in classes with the real openai SDK types so the shim stays in sync with the SDK schema (same rationale as the EasyInputMessageParam input-side change already merged in #48002).

Changes

  • Replace _Usage / _ChatMessage / _Choice / _ChatCompletion with:
    • _to_usage(...) -> openai.types.CompletionUsage
    • _to_chat_completion(...) -> openai.types.chat.ChatCompletion (built from Choice + ChatCompletionMessage)
  • _finish_reason now returns the chat-completions finish_reason Literal and clamps any unexpected Responses incomplete_details.reason to stop so Choice validation cannot fail.

Why

  • Schema-drift protection — if openai restructures the chat-completion shape, this is caught at type-check time instead of silently breaking (the reviewer's point).
  • Fixes a latent bug — the prompty response formatter calls response.model_dump() on the tool-call path; the hand-written _ChatCompletion did not provide it, so a real ChatCompletion closes that gap.
  • openai is already a hard dependency (openai>=1.108.0), so importing these types is safe.

Testing

  • 29 test_byo_judge.py unit tests pass; black clean.
  • Manual admin-connected E2E: 72/72 OK across 18 prompty evaluators x 4 connection types (APIM key/MI, ModelGateway key/OAuth2) against a clean, non-editable install of this branch.

Address PR review (posaninagendra): re-shape the Responses API result into the
real openai chat-completion types instead of hand-written stand-ins. Replace the
_Usage/_ChatMessage/_Choice/_ChatCompletion classes with _to_usage (-> openai
CompletionUsage) and _to_chat_completion (-> openai ChatCompletion with Choice /
ChatCompletionMessage). This keeps the shim in sync with the SDK schema (same
rationale as the EasyInputMessageParam input change) and, as a bonus, fixes a
latent gap: the prompty formatter calls response.model_dump() on the tool-call
path, which the hand-written _ChatCompletion did not provide.

_finish_reason now returns the chat-completions finish_reason Literal (clamping
any unexpected Responses incomplete reason to 'stop') so Choice validation cannot
fail. Runtime behavior is unchanged for the judge path; 29 byo unit tests pass and
the 18x4 admin-connected matrix is 72/72 OK.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b11202e6-6a52-4777-bed1-9c48730a63c3
Copilot AI review requested due to automatic review settings July 21, 2026 13:20
@shrutiyer
shrutiyer requested a review from a team as a code owner July 21, 2026 13:20
@github-actions github-actions Bot added the Evaluation Issues related to the client library for Azure AI Evaluation label Jul 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Replaces handwritten BYO judge response adapters with OpenAI SDK response types.

Changes:

  • Adds typed conversion helpers for usage and chat completions.
  • Normalizes Responses API finish reasons.
  • Updates BYO judge unit tests for the new helpers.

Reviewed changes

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

File Description
_byo_judge.py Constructs OpenAI SDK completion objects.
test_byo_judge.py Updates adapter and finish-reason tests.

Copilot AI review requested due to automatic review settings July 21, 2026 19:56

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 2 out of 2 changed files in this pull request and generated no new comments.

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

Labels

Evaluation Issues related to the client library for Azure AI Evaluation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants