Skip to content

Bug: SchemaOptimizer leaves a dangling $ref when a model field is named "description" #5603

Closed

Description

@aniketwaghh

Browser Use Version

d2fcda5 (0.13.8)

Bug Description

SchemaOptimizer.create_optimized_json_schema inlines every $ref and drops $defs. It does that by walking the schema and dispatching on JSON Schema keyword names, but it walks into properties maps too, and the keys in there are the user's field names, not keywords.

So a model field named description lands in the elif key == 'description': branch (browser_use/llm/schema.py:57), which copies the value through verbatim and never recurses. If that field is a nested model, its {"$ref": "#/$defs/..."} is never inlined, and $defs has already been stripped, so the schema we hand the provider points at nothing.

This is the same bug #2324 fixed for a field named title by adding the in_properties flag. description was missed.

Reproduce with no API key:

from pydantic import BaseModel
from browser_use.llm.schema import SchemaOptimizer

class Details(BaseModel):
	summary: str

class Article(BaseModel):
	headline: str
	description: Details

print(SchemaOptimizer.create_optimized_json_schema(Article))

On d2fcda5:

{'properties': {'headline': {'type': 'string'},
                'description': {'$ref': '#/$defs/Details'}},
 'required': ['headline', 'description'],
 'type': 'object',
 'additionalProperties': False}

#/$defs/Details is not in the document, and jsonschema 4.26.0 refuses it:

_WrappedReferencingError: PointerToNowhere: '/$defs/Details' does not exist within
{'properties': {'headline': {'type': 'string'}, 'description': {'$ref': '#/$defs/Details'}}, ...}

Same thing through the agent path with Agent(output_model_schema=Article) / Tools(output_model=Article):

DANGLING /properties/action/items/anyOf[0]/properties/done/properties/data/properties/description/$ref -> #/$defs/Details

That dict goes straight into response_format with strict: True in ChatOpenAI (browser_use/llm/openai/chat.py:224-232), into input_schema on the Anthropic ToolParam, and into the Bedrock/Gemini/Groq tool specs.

A field named properties is affected more mildly: in_properties=True leaks into the field's own schema, so it keeps its metadata title.

I checked every other JSON Schema keyword that has a branch in that loop. Fields named title, type, required, items, anyOf, default, pattern, minimum, maximum and minItems all come out correct today. It is only description and properties.

Failing Python Code

from pydantic import BaseModel
from browser_use import Agent
from browser_use.llm import ChatOpenAI

class Details(BaseModel):
	summary: str
	bullets: list[str]

class Article(BaseModel):
	headline: str
	description: Details

agent = Agent(
	task='open example.com and summarise it',
	llm=ChatOpenAI(model='gpt-4.1-mini'),
	output_model_schema=Article,
)
# the done-action schema sent to the model contains "$ref": "#/$defs/Details" with no $defs

LLM Model

any provider that uses structured output

Operating System & Browser Versions

macOS 15 (the bug is in a pure function, no browser involved)

Activity

  1. aniketwaghh commented on Aug 30, 2026

    @aniketwaghh
    ContributorAuthor

    Correcting two things in this report after a fuller sweep on d2fcda5.

    I said it was description and properties. properties is fine - I claimed it holds on to a metadata title and it does not.

    I also missed two that are worse. additionalProperties and $defs are in skip_fields, so a field with either name is skipped and vanishes from the schema entirely, rather than being left with a dangling pointer. Every keyword as a field name:

    additionalProperties   DROPPED
    $defs                  DROPPED
    description            dangling $ref
    title, type, properties, items, anyOf, required, default,
    pattern, minimum, maximum, minItems, enum, format, allOf,
    oneOf, const, examples, nullable                            ok
    

    The dropped ones fail silently, which is the worse half of this - nothing raises, the field is simply never offered to the model.

    #5605 fixes all three, because the in_properties check sits ahead of skip_fields.

  2. added a commit that references this issue on Aug 30, 2026
    5def56e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions