fix: add additionalProperties: false to structured output schemas for Databricks compatibility#2308
Merged
sfc-gh-jreini merged 3 commits intotruera:mainfrom Dec 11, 2025
Conversation
… Databricks compatibility This fix enables TruLens structured outputs to work with Databricks AI Gateway and other providers that require strict JSON schema validation. ## Problem Databricks model serving endpoints require `additionalProperties: false` in JSON schemas for structured outputs (response_format). Without this, TruLens feedback evaluations fail with: ``` Invalid schema for response_format 'ChainOfThoughtResponse': In context=(), 'additionalProperties' is required to be supplied and to be false. ``` ## Solution Add `model_config = ConfigDict(extra="forbid")` to Pydantic models in `output_schemas.py`. This causes Pydantic to include `additionalProperties: false` in the generated JSON schema, which satisfies Databricks' requirements. ## Changes - Modified `BaseFeedbackResponse` and `ChainOfThoughtResponse` models - Added comprehensive unit tests to verify schema generation and runtime behavior - All existing tests pass (11/11 OpenAI capability tests) ## Backward Compatibility This change is backward compatible: - JSON schema output changes from implicit to explicit `additionalProperties: false` - Runtime behavior now rejects extra fields (stricter validation is generally safe) - No API or interface changes Fixes: truera#2307 Signed-off-by: Debu Sinha <debusinha2009@gmail.com> Signed-off-by: debu-sinha <debusinha2009@gmail.com>
Contributor
|
Thanks again for contributing! Can you update the API tests by running |
Signed-off-by: debu-sinha <debusinha2009@gmail.com>
Contributor
Author
|
@sfc-gh-jreini I've set up Python 3.11 locally and ran |
Signed-off-by: debu-sinha <debusinha2009@gmail.com>
sfc-gh-jreini
approved these changes
Dec 11, 2025
Contributor
sfc-gh-jreini
left a comment
There was a problem hiding this comment.
works well on my side for non-dbrx providers 👍
9 tasks
Merged
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.
Summary
This PR fixes a compatibility issue with Databricks AI Gateway that prevents TruLens structured outputs from working with Databricks model serving endpoints.
Fixes: #2307
cc: @joshreini1 @piotrm0 @sfc-gh-dkurokawa
Problem
Databricks model serving endpoints require
additionalProperties: falsein JSON schemas for structured outputs (when usingresponse_format). Without this property, TruLens feedback evaluations fail with:This affects users who want to use TruLens with:
Solution
Add
model_config = ConfigDict(extra="forbid")to Pydantic models inoutput_schemas.py. This causes Pydantic to includeadditionalProperties: falsein the generated JSON schema.Code Change
Schema Before (without the fix):
{ "properties": { "criteria": {"description": "The criteria for the evaluation.", "title": "Criteria", "type": "string"}, "supporting_evidence": {"description": "Supporting evidence...", "title": "Supporting Evidence", "type": "string"}, "score": {"description": "The score based on the given criteria.", "title": "Score", "type": "integer"} }, "required": ["criteria", "supporting_evidence", "score"], "title": "ChainOfThoughtResponse", "type": "object" }Schema After (with the fix):
{ "additionalProperties": false, "properties": { "criteria": {"description": "The criteria for the evaluation.", "title": "Criteria", "type": "string"}, "supporting_evidence": {"description": "Supporting evidence...", "title": "Supporting Evidence", "type": "string"}, "score": {"description": "The score based on the given criteria.", "title": "Score", "type": "integer"} }, "required": ["criteria", "supporting_evidence", "score"], "title": "ChainOfThoughtResponse", "type": "object" }Changes
src/feedback/trulens/feedback/output_schemas.pymodel_config = ConfigDict(extra="forbid")to both modelstests/unit/test_output_schemas.pyTesting
Test Verification
Backward Compatibility
This change is backward compatible:
additionalProperties: falseRelated Issues