browser-use/browser-use · error · AttributeError
module '{__name__}' has no attribute '{name}'
Error message
module '{__name__}' has no attribute '{name}' What it means
The dynamic extraction-schema compiler (used by the `extract` tool to turn a JSON Schema into a Pydantic model) only supports a structural subset of JSON Schema. `_check_unsupported` rejects composition/reference keywords listed in _UNSUPPORTED_KEYWORDS ($ref, allOf, anyOf, oneOf, not, etc.) because there is no reliable translation to a flat create_model field map. The error is raised at schema-compile time, before any LLM call or page extraction happens.
Source
Thrown at browser_use/__init__.py:135
"""Lazy import mechanism - only import modules when they're actually accessed."""
if name in _LAZY_IMPORTS:
module_path, attr_name = _LAZY_IMPORTS[name]
try:
from importlib import import_module
module = import_module(module_path)
if attr_name is None:
# For modules like 'models', return the module itself
attr = module
else:
attr = getattr(module, attr_name)
# Cache the imported attribute in the module's globals
globals()[name] = attr
return attr
except ImportError as e:
raise ImportError(f'Failed to import {name} from {module_path}: {e}') from e
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
__all__ = [
'Agent',
'BrowserSession',
'Browser', # Alias for BrowserSession
'BrowserProfile',
'Controller',
'DomService',
'SystemPrompt',
'ActionResult',
'ActionModel',
'AgentHistoryList',
# Chat models
'ChatOpenAI',
'ChatGoogle',
'ChatAnthropic',
'ChatAnthropicBedrock',View on GitHub (pinned to 6c73fced2f)
Solutions
- Flatten the schema by hand: inline every $ref, and replace anyOf/oneOf/allOf unions with a single concrete type or a type array like {"type": ["string", "null"]} if supported by your version.
- Replace optional-union patterns with the property flagged in `required` omission plus a nullable type representation the compiler accepts.
- Keep extraction schemas small and hand-written for this tool — a flat object of scalar/array/object properties with enums as string enums.
- If you need full JSON Schema unions, define a static Pydantic model and pass that instead of a raw schema where the API allows it.
Example fix
# before
schema = {
"type": "object",
"properties": {
"price": {"anyOf": [{"type": "number"}, {"type": "null"}]},
"address": {"$ref": "#/$defs/address"}
}
}
# after
schema = {
"type": "object",
"properties": {
"price": {"type": "number"},
"address": {"type": "object", "properties": {"city": {"type": "string"}, "zip": {"type": "string"}}}
}
} Defensive patterns
Strategy: validation
Validate before calling
UNSUPPORTED = {'$ref', '$defs', 'allOf', 'anyOf', 'oneOf', 'not'}
def schema_is_supported(node: dict) -> bool:
if not isinstance(node, dict):
return True
if any(kw in node for kw in UNSUPPORTED):
return False
return all(schema_is_supported(v) for v in node.get('properties', {}).values()) Type guard
def is_flat_extraction_schema(schema: dict) -> bool:
return (
isinstance(schema, dict)
and schema.get('type') == 'object'
and bool(schema.get('properties'))
and schema_is_supported(schema)
) Try / catch
from browser_use.tools.extraction.schema_utils import schema_to_model
try:
model = schema_to_model(schema)
except ValueError as e:
if 'Unsupported JSON Schema keyword' in str(e):
schema = flatten_refs_and_unions(schema) # your normalizer
model = schema_to_model(schema) Prevention
- Hand-write extraction schemas instead of copying from OpenAPI specs.
- Derefence $refs and inline unions with a preprocessing step before passing schemas to extract.
- Add a unit test that compiles every schema your app uses with schema_to_model at import time.
When it happens
Trigger: Passing an `output_model_schema` / extraction schema that contains any of the unsupported keywords at the top level or in any nested node (e.g. {"type":"object","properties":{"x":{"anyOf":[{"type":"string"},{"type":"null"}]}}} or a $ref to a shared definition). Also triggered by OpenAPI-derived schemas that ubiquitously use $ref/anyOf.
Common situations: Copying a schema from an OpenAPI spec or JSON-Schema-2020-12 source into extract(); modeling optional fields with anyOf [T, null] instead of type arrays; trying to reuse definitions via $defs/$ref for DRY schemas.
Related errors
- Failed to find DOM element based on backendNodeId, maybe pag
- Failed to click element: {js_e}
- Failed to import {name} from {module_path}: {e}
- Failed to click element: {e}
- Failed to get object ID for element
AI-assisted analysis of browser-use/browser-use@6c73fced2f (2026-08-14).
Data as JSON: /api/errors/5472ca6d75806be8.
Report an issue: GitHub.