Skip to content

fix(llm): keep Field descriptions when flattening $ref in optimized schemas - #6132

Open
surlymochan wants to merge 2 commits into
browser-use:mainfrom
surlymochan:fix/schema-ref-field-description
Open

surlymochan wants to merge 2 commits into
browser-use:mainfrom
surlymochan:fix/schema-ref-field-description

Conversation

@surlymochan

@surlymochan surlymochan commented Oct 19, 2026 •

Copy link
Copy Markdown

What

SchemaOptimizer.create_optimized_json_schema inlines $defs references and then merges the keywords that sat next to the $ref. The merge always kept the referenced model's docstring and skipped a sibling description, so a field-level Field(description=...) on a nested model was silently dropped from the schema sent to the LLM whenever that model has a docstring.

class Address(BaseModel):
	"""Postal address of the store"""
	city: str = Field(description='City name')

class Product(BaseModel):
	"""A product listing found on the page"""
	name: str
	address: Address = Field(description='Where the product is available')

SchemaOptimizer.create_optimized_json_schema(Product)['properties']['address']['description']
# main:  'Postal address of the store'
# fixed: 'Where the product is available'

Pydantic emits the field description as a sibling of the $ref precisely 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 treats description the same.

Verification

  • New test test_optimizer_keeps_field_description_when_flattening_ref in tests/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 --check on the changed files: clean.

Summary by cubic

Field-level descriptions on nested models are no longer dropped when SchemaOptimizer flattens $ref entries. The description written next to the $ref now takes precedence over the referenced model's docstring, matching the behavior when the model has no docstring.

  • Adds a regression test that also verifies nested field descriptions remain intact.
  • No migration or rollout steps required.

Written for commit 7f683c1. Summary will update on new commits.

View guided diff

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

View guided diff | Re-trigger cubic

sun04222 added a commit to sun04222/browser-use that referenced this pull request Oct 23, 2026
@CLAassistant

CLAassistant commented Oct 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mintlify

mintlify Bot commented Nov 22, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 7f683c1.

Approve preview

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants