Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix(llm): preserve schema-keyword field names
MagMuellerc48b1c99289d
diff --git a/browser_use/llm/schema.py b/browser_use/llm/schema.pyindex d4e01be42..75c33d07a 100644--- a/browser_use/llm/schema.py+++ b/browser_use/llm/schema.py@@ -45,11 +45,16 @@ class SchemaOptimizer:skip_fields = ['additionalProperties', '$defs']for key, value in obj.items():+ # Keys inside `properties` are user field names, not schema keywords.+ if in_properties:+ optimized[key] = optimize_schema(value, defs_lookup)+ continue+if key in skip_fields:continue- # Skip metadata "title" unless we're iterating inside an actual `properties` map- if key == 'title' and not in_properties:+ # Skip metadata "title"+ if key == 'title':continue# Preserve FULL descriptions without truncation, skip empty onesdiff --git a/tests/ci/models/test_llm_schema_optimizer.py b/tests/ci/models/test_llm_schema_optimizer.pyindex 5aa452b05..e3e472732 100644--- a/tests/ci/models/test_llm_schema_optimizer.py+++ b/tests/ci/models/test_llm_schema_optimizer.py@@ -74,3 +74,22 @@ def test_gemini_schema_retains_required_fields():required_fields = set(schema['required'])assert {'price', 'title'}.issubset(required_fields), 'Mandatory fields must stay required for Gemini.'+++def test_optimizer_treats_property_names_as_data_not_schema_keywords():+ """Nested fields named after schema keywords must still have their refs flattened."""++ class Details(BaseModel):+ summary: str++ class Article(BaseModel):+ description: Details+ properties: Details++ schema = SchemaOptimizer.create_optimized_json_schema(Article)++ assert '$defs' not in schema+ for field_name in ('description', 'properties'):+ field_schema = schema['properties'][field_name]+ assert '$ref' not in field_schema+ assert field_schema['properties']['summary']['type'] == 'string'