-
Notifications
You must be signed in to change notification settings - Fork 638
[FEAT] Support JSON Schema in Responses #1177
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
Merged
romanlutz
merged 81 commits into
Azure:main
from
riedgar-ms:riedgar-ms/selfask-scorer-fix-01
Dec 30, 2025
Merged
Changes from 52 commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
073cf62
Drafting a quick test script
riedgar-ms 244f2cf
Corrected JSON support
riedgar-ms 9fccc5b
Expand testing
riedgar-ms dd36ea2
Don't need this
riedgar-ms 170b16b
Some small refinements
riedgar-ms dd56600
Draft unit test updates
riedgar-ms 8df25b9
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 5405dec
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms fa4ca37
Proposal for schema smuggling
riedgar-ms 7390271
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 320d58c
Linting issues
riedgar-ms 842cd03
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 80e8cd4
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 2003466
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 45cb825
Add the JSONResponseConfig class
riedgar-ms ec4efaa
Better name
riedgar-ms 1eb4395
Start on other changes
riedgar-ms 29fdb2f
Next changes
riedgar-ms 2c8e919
Try dealing with some linting
riedgar-ms 9009edf
More changes....
riedgar-ms d899af4
Correct responses setup
riedgar-ms c78f819
blacken
riedgar-ms 45f73a6
Fix a test....
riedgar-ms becb214
Fix reponses tests
riedgar-ms f37d070
Fix chat target tests
riedgar-ms 6072ae3
blacken
riedgar-ms 4262cd7
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 970c4f2
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 55502ff
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 388f138
Resync with origin/main
riedgar-ms b6182e9
Merge from main
riedgar-ms 630842a
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
4da3b9d
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms fd03bba
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 21fe8a0
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 48c61cc
Switching auth
riedgar-ms cf71d2d
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms d231d79
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms c8b4d0d
Working on next bit
riedgar-ms 03c59a6
Get one test working again...
riedgar-ms 5275b14
Should be the final test working (plus linting)
riedgar-ms 9dfdcf6
Think this is the other place?
riedgar-ms 5cef55d
Missing import?
riedgar-ms bea538c
And another
riedgar-ms e5bbea0
Sort imports
riedgar-ms f325976
A bad merge
riedgar-ms 271ea14
More missed merges
riedgar-ms e90e409
ruff fix
riedgar-ms b1a7fdb
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms a272af9
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms eee44be
Need a doc string
riedgar-ms 41f576c
Forgot doc hook
riedgar-ms 955ce14
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 5c53356
Address ruff issues
riedgar-ms 8b746d5
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 3cd53b2
Resolve transpondian confusion
riedgar-ms 489b897
Fixing merge
riedgar-ms b9faa93
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 7aee618
Don't need to quote self in type annotation
riedgar-ms 5ebe871
Fix indent in docstring
riedgar-ms fb9ebc0
Put links in docstring
riedgar-ms 97b64e3
Better naming
riedgar-ms b5cc797
Update tests
riedgar-ms 3ad5b7d
blacken
riedgar-ms 91a88b8
Another blacken
riedgar-ms ee160f9
Python 3.10 grrrr....
riedgar-ms 573d13b
Run isort
riedgar-ms ee0eb39
Drafting a notebook update
riedgar-ms 6b2dd82
Update notebook
riedgar-ms 560d4e9
Moving JsonResponseConfig to private
riedgar-ms 406c7b7
Run isort on notebook
riedgar-ms 5edfd65
Add section on JSON to the chat notebook
riedgar-ms ceb512d
Get the notebook fixed and regenerated
riedgar-ms 693ced5
Fix OpenAI docs issue
riedgar-ms 75f7e31
Linting notebooks
riedgar-ms 2481ca6
Try running pre-commit
riedgar-ms e75d561
exec notebooks
romanlutz f2eae6c
Merge branch 'riedgar-ms/selfask-scorer-fix-01' of https://github.com…
romanlutz c2cce69
rerun notebooks and pre-commit
romanlutz d6e0c7b
Switch auth back for tests
riedgar-ms 4f7c536
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms 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
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from dataclasses import dataclass | ||
| from typing import Any, Dict, Optional | ||
|
|
||
|
|
||
| @dataclass | ||
| class JsonResponseConfig: | ||
| """ | ||
| Configuration for JSON responses (with OpenAI). | ||
| """ | ||
|
|
||
| enabled: bool = False | ||
| schema: Optional[Dict[str, Any]] = None | ||
| schema_name: str = "CustomSchema" | ||
| strict: bool = True | ||
|
|
||
| @classmethod | ||
| def from_metadata(cls, *, metadata: Optional[Dict[str, Any]]) -> "JsonResponseConfig": | ||
riedgar-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if not metadata: | ||
| return cls(enabled=False) | ||
|
|
||
| response_format = metadata.get("response_format") | ||
| if response_format != "json": | ||
| return cls(enabled=False) | ||
|
|
||
| schema_val = metadata.get("json_schema") | ||
| if schema_val: | ||
| if isinstance(schema_val, str): | ||
| try: | ||
| schema = json.loads(schema_val) if schema_val else None | ||
| except json.JSONDecodeError: | ||
| raise ValueError(f"Invalid JSON schema provided: {schema_val}") | ||
| else: | ||
| schema = schema_val | ||
|
|
||
| return cls( | ||
| enabled=True, | ||
| schema=schema, | ||
| schema_name=metadata.get("schema_name", "CustomSchema"), | ||
| strict=metadata.get("strict", True), | ||
romanlutz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| return cls(enabled=True) | ||
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
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
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.