schema_dict_to_pydantic_model TypeError on JSON Schema type arrays → extract falls back to free-text
Description
Standard JSON Schema / OpenAPI nullable fields use "type": ["string", "null"] (and other type unions). In browser_use/tools/extraction/schema_utils.py, _resolve_type does _PRIMITIVE_MAP.get(json_type, str) when json_type is a list, which raises TypeError: unhashable type: 'list'.
extract() in browser_use/tools/service.py catches that TypeError and clears output_schema, falling back to free-text extraction. So Agent(extraction_schema=...) / extract(output_schema=...) never produce validated structured JSON for these common schemas.
The proprietary "nullable": true flag works; the standard type-array form does not.
Environment
browser-use==0.13.10- Offline unit repro (no live API / no browser)
Repro
from browser_use.tools.extraction.schema_utils import schema_dict_to_pydantic_model
schema = {
"type": "object",
"properties": {
"nickname": {"type": ["string", "null"]},
},
"required": [],
}
try:
schema_dict_to_pydantic_model(schema)
except TypeError as e:
print(type(e).__name__, e) # TypeError: unhashable type: 'list'
# Contrast: proprietary nullable flag works
ok = {
"type": "object",
"properties": {
"nickname": {"type": "string", "nullable": True},
},
}
model = schema_dict_to_pydantic_model(ok)
print(model.model_fields["nickname"].annotation) # str | NoneObserved (browser-use==0.13.10)
{"type": ["string", "null"]}→TypeError: unhashable type: 'list'{"type": "string", "nullable": true}→ buildsstr | NoneOK- Callers that catch
TypeErrorsilently drop structured extraction
Expected
JSON Schema type arrays (especially nullable unions with "null") should build a Pydantic model, same as "nullable": true.
Suggested fix
When type is a list, map each entry through _PRIMITIVE_MAP, treat "null" as optional (T | None), and handle other unions explicitly. Do not dict.get with a list key.
Impact
Any OpenAPI-exported or JSON-Schema-draft extraction schema with nullables silently loses structured mode; agents get unconstrained free text instead of schema-validated objects.
Happy to open a PR.
Source: browser-use/browser-use