Add response_format support to model settings - #258
Open
juliendenize wants to merge 2 commits into
Open
Conversation
juliendenize
force-pushed
the
feat/response-format-model-settings
branch
from
July 7, 2026 12:53
6043d64 to
7b675a3
Compare
juliendenize
force-pushed
the
feat/response-format-model-settings
branch
from
July 7, 2026 13:02
7b675a3 to
bc92712
Compare
juliendenize
marked this pull request as ready for review
July 7, 2026 13:13
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Some models constrain their output to a JSON schema. To support this end-to-end, the encoded
ModelSettings(which is what the tokenizer emits to condition the model) needs to carry the JSON schema derived from a request'sresponse_format. This adds first-classresponse_format/ JSON-schema support so those models can be driven correctly through mistral-common.Summary
json_schemasupport toResponseFormat:ResponseFormats.json_schemaenum value.JsonSchemamodel (name,description,schemaaliased tocustom_schema,strict) with Draft 7 validation.ResponseFormat.get_schema()resolves the effective schema: custom schema forjson_schema, generic object/arrayanyOfforjson_object,Nonefortext.json_schemafield to encodedModelSettings(tokenizer >= v15).ModelSettingsBuilder/FieldBuilderto a typedInputT -> OutputTconvert-then-validate design so a request field (e.g.response_format) can be converted into a different settings field (e.g.json_schema), via_SETTINGS_TO_CONV_FIELDS_MAP.JSONSchemaBuilderconverts aResponseFormatto a validated schema dict.mistral_common/utils/json_utils.pywithvalidate_json_schema_by_draft7.ChatCompletionRequest.to_openainow serializesby_alias=Truesoschemais emitted correctly.Reviewer guide
Real logic:
src/mistral_common/protocol/instruct/request.py— newJsonSchema,ResponseFormat.get_schema(),ModelSettings.json_schema,by_aliasserialization.src/mistral_common/tokens/tokenizers/model_settings_builder.py— theFieldBuildergeneric refactor (convert vs validate split) and newJSONSchemaBuilder+ field mapping. Most careful review here.New:
src/mistral_common/utils/json_utils.py(+utils/__init__.py) — Draft 7 schema validation helper.Tests:
tests/test_model_settings.py,tests/test_request.py,tests/test_json_utils.py,tests/test_converters.py,tests/test_tokenizer_v15.py— coverage for the new behavior.Test plan
pytest tests/test_model_settings.py tests/test_request.py tests/test_json_utils.py tests/test_converters.py tests/test_tokenizer_v15.py— 171 passed.ruff format --check,ruff check,mypyon changed sources — all clean.