Repository navigation
Add response_format support to model settings (no version bump) - #355
Conversation
2e98ddb to
50a5f5f
Compare
| r"""Render the response format's schema for model-settings encoding.""" | ||
| return input_value.get_schema() | ||
|
|
||
| def _validate_built_value(self, field_name: str, value: JSONSchemaDict) -> None: |
There was a problem hiding this comment.
do we need this function even?
There was a problem hiding this comment.
yeah to implement parent class
There was a problem hiding this comment.
but in the other repo this is not used?
| exclude={"messages", "tools", "truncate_for_context_length", "tool_choice"}, exclude_none=True | ||
| exclude={"messages", "tools", "truncate_for_context_length", "tool_choice"}, | ||
| exclude_none=True, | ||
| by_alias=True, |
There was a problem hiding this comment.
are we confident that there is recursively a single alias? should we test for that?
There was a problem hiding this comment.
Yes: JsonSchema.custom_schema → schema is the only alias in src/, and messages/tools are excluded from this dump anyway (serialized separately). test_to_openai_renames_custom_schema_to_schema covers it. I didn't add a guard test: aliases exist to match OpenAI field names, so by_alias=True is the behavior we want for any future alias too.
2def7a7 to
12100ca
Compare
Committed with AI assistance.
Committed with AI assistance.
Committed with AI assistance.
Committed with AI assistance.
Remove the partially-migrated tests/unit/ tree. The migration to unit/integration structure was started prematurely; keep all tests in the flat tests/ directory until the full migration is planned. Removes: - tests/unit/mistral_common/tokens/tokenizers/test_model_settings_builder.py - tests/unit/mistral_common/tokens/tokenizers/test_tokenizer_v15.py - tests/unit/mistral_common/experimental/app/test_models.py Committed with AI assistance.
The strict field is accepted, stored, and round-tripped through OpenAI conversion, but no code path consults it. get_schema() returns the custom schema unconditionally regardless of strict. Tighten the docstring to make this explicit so readers don't expect strict=False to loosen the constraint. Committed with AI assistance.
… None check - Remove ReasoningEffortType TypeVar; use ReasoningEffort | None directly in ModelSettingsConv Protocol (Joachim's suggestion) - Remove redundant if value is not None in JSONSchemaBuilder.validate_built_value; the check in _validate_built_value handles None (Joachim's suggestion) - Keep ModelSettingsConv Protocol for duck typing; it documents the required attributes for build_settings even if ChatCompletionRequest is the only caller Committed with AI assistance.
Require JSON schemas during ResponseFormat validation, remove duplicate runtime checks, and make chat request typing explicit. Drop the unused pickle-specific enum subclass and default invariant JSON schema builder options at the class definition. Committed with AI assistance.
Committed with AI assistance.
Add purpose-aware schema rendering so grammar consumers can honor the OpenAI strict flag without weakening the schema encoded in model settings. Committed with AI assistance.
Committed with AI assistance.
Raise InvalidRequestException for invalid JSON schemas in model settings and cover it, share Draft 7 validation with the tool validator, drop the redundant validation in build_settings, document top-level-only key sorting, remove tests that only exercised Pydantic, and tidy docstrings and call sites. Committed with AI assistance.
Committed with AI assistance.
Rename the settings-to-request field map after the removed protocol and test that it stays in sync with the builder fields. Committed with AI assistance.
A schema attached to a text or json_object response format was silently ignored; ResponseFormat validation now rejects it. Committed with AI assistance.
This reverts commit 18217fc. OpenAI's spec does not forbid a json_schema on text or json_object response formats and vLLM accepts and ignores it, so rejecting it would only break compatible clients. Committed with AI assistance.
12100ca to
af01115
Compare
There was a problem hiding this comment.
hmm just realized that technically here it should be {"anyOf": [{"type": "object"}, {"type": "array"}]} no?
There was a problem hiding this comment.
yep good catch i updated it
…rammar fallback (#401)

Note
Supersedes #258. Identical changes, minus the version bump to 1.13.0. Keeping the version at 1.12.0 means the branch can be installed directly without colliding with the eventual published 1.13.0 release, while we keep adding to mistral-common:
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. Grammar consumers also need purpose-specific schema selection: strict grammar uses the custom schema, while non-strict grammar uses a generic object schema.Summary
json_schemasupport toResponseFormat:ResponseFormats.json_schemaenum value.JsonSchemamodel (name,description,custom_schemaaliased toschema,strict) with Draft 7 validation.ResponseFormatvalidation requires a schema forjson_schema.SchemaRenderingModeand purpose-awareResponseFormat.get_schema():model_settingsalways returns the custom schema.grammarreturns the custom schema when strict, or a generic object schema when non-strict.json_objectreturns a generic object/arrayanyOf;textreturnsNone.json_schemato encodedModelSettings(tokenizer >= v15). Encoding now sorts only the top-level setting names instead ofsort_keys=True, so the schema's property order (which conveys generation order) is kept.ModelSettingsBuilder/FieldBuilderto a typedInputT -> OutputTconvert-then-validate design, allowingresponse_formatto produce thejson_schemasetting.JSONSchemaBuilderand Draft 7 validation viamistral_common/utils/json_utils.py. Invalid schemas in model settings raiseInvalidRequestException; tool-schema validation reuses the same helper and still raisesInvalidToolSchemaException(Invalid tool schema: ...).ChatCompletionRequest.to_openaiserializes by alias soschemais emitted correctly.get_schema()selects the schema for its consumer; grammar generation itself remains the caller's responsibility.Reviewer guide
src/mistral_common/protocol/instruct/request.py—JsonSchema,SchemaRenderingMode, purpose-specific schema selection, and OpenAI serialization.src/mistral_common/tokens/tokenizers/model_settings_builder.py— typed field conversion and schema validation for model settings.src/mistral_common/utils/json_utils.py— Draft 7 schema validation helper.Test plan
pytest tests/— 1619 passed, 17 skipped.src/andtests/— clean.