Repository navigation
fix(llm): keep Field descriptions when flattening $ref in optimized schemas - #6132
Open
surlymochan wants to merge 2 commits into
Open
surlymochan wants to merge 2 commits into
surlymochan wants to merge 2 commits into
Conversation
SchemaOptimizer inlined $defs and merged sibling keywords, but always preferred the referenced model's docstring over a description written next to the $ref (Field(description=...)), silently dropping the field-level description from the schema sent to the LLM. Let the siblings win once the ref is inlined.
sun04222
added a commit
to sun04222/browser-use
that referenced
this pull request
Oct 23, 2026
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This branch has not been deployed
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.
What
SchemaOptimizer.create_optimized_json_schemainlines$defsreferences and then merges the keywords that sat next to the$ref. The merge always kept the referenced model's docstring and skipped a siblingdescription, so a field-levelField(description=...)on a nested model was silently dropped from the schema sent to the LLM whenever that model has a docstring.Pydantic emits the field description as a sibling of the
$refprecisely because it describes that field, and it's the more specific text, so it should win once the ref is inlined (as it already does when the referenced model has no docstring). Other sibling keywords were already merged this way; this just treatsdescriptionthe same.Verification
test_optimizer_keeps_field_description_when_flattening_refintests/ci/models/test_llm_schema_optimizer.py: fails on main, passes with the fix.pytest tests/ci/models/test_llm_schema_optimizer.py: 4 passed.ruff check/ruff format --checkon the changed files: clean.Summary by cubic
Field-level descriptions on nested models are no longer dropped when
SchemaOptimizerflattens$refentries. The description written next to the$refnow takes precedence over the referenced model's docstring, matching the behavior when the model has no docstring.Written for commit 7f683c1. Summary will update on new commits.