Skip to content

fix(schema): keep user fields named after stripped keywords in remove passes - #5893

Open
rubenmarcus wants to merge 10 commits into
browser-use:mainfrom
rubenmarcus:fix/schema-cleanup-keep-keyword-named-fields
Open

rubenmarcus wants to merge 10 commits into
browser-use:mainfrom
rubenmarcus:fix/schema-cleanup-keep-keyword-named-fields

Conversation

@rubenmarcus

@rubenmarcus rubenmarcus commented Sep 25, 2026 •

Copy link
Copy Markdown

Fixes #5829.

Problem

When remove_defaults and/or remove_min_items are set, the final remove_forbidden_fields pass pops the keys default, minItems, and min_items from every dict it walks, including the properties mapping, where those strings are user field names. A Pydantic output model with fields named default, minItems, or min_items ends up with those entries deleted from properties while required still lists them and the strict pass has set additionalProperties: false: the schema is unsatisfiable and the LLM cannot produce a valid response.

Fix

The pass now tracks whether it is inside a properties mapping. The mapping level itself never has keys popped (names there are data, not schema keywords); each property's schema is still processed normally, so default values and minItems annotations are stripped where they actually appear. This mirrors the earlier fix in test_optimizer_treats_property_names_as_data_not_schema_keywords, which covered the flattening pass but not the remove passes.

Verification

$ pytest tests/ci/models/test_llm_schema_optimizer.py -k keep_fields
1 failed   # on main: fields dropped from properties while still required
$ pytest tests/ci/models/test_llm_schema_optimizer.py
4 passed   # with this change
$ pytest tests/ci/models/
126 passed, 7 skipped

The new regression model uses fields named default, minItems, and min_items plus a field with a default value, asserting the names survive in both properties and required while the default value is still stripped from annotations.

Head 7809760d1 merges upstream main (b49a68e40). That side of the merge touches README.md, examples/models/fireworks.py and pyproject.toml only, so browser_use/llm/schema.py and the test file are unchanged from the previous head e82fa21cc.

Disclosure: this PR was prepared with AI assistance (GLM via Oh My Pi) and reviewed before submission.


Summary by cubic

Fixes #5829. remove_defaults and remove_min_items no longer delete user fields named default, minItems, or min_items from the properties mapping, which previously left the schema unsatisfiable under additionalProperties: false. The removal pass now treats keys inside a properties mapping as data rather than schema keywords, while still stripping default values and minItems annotations from each property's schema. Adds a regression test covering fields named after the stripped keywords plus a field with a default value.

Written for commit e82fa21. Summary will update on new commits.

View guided diff

@CLAassistant

CLAassistant commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.

All reported issues were addressed across 2 files

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

Fix all with cubic | Re-trigger cubic

Comment thread browser_use/llm/schema.py Resolved
@rubenmarcus

Copy link
Copy Markdown
Author

integrations/test_anthropic_browser_use fails on the current head with ImportError: cannot import name 'BetaBrowserScreenshotResult' from 'anthropic.tools.browser'. The pyright hook in code-style and the type-checker job fail on the same imports (browser_use/integrations/anthropic/browser_use.py:28-31, examples/integrations/toolsets-for-claude/quickstart.py:10).

This diff touches browser_use/llm/schema.py and tests/ci/models/test_llm_schema_optimizer.py, so there's nothing to change on the branch. The same three checks fail identically on 8 other open PRs (#6067, #6004, #6066, #6064, #6061, #6059, #6056, #5534). Main's last run (37653720138, Oct 7, the commit that touched these files) was green, so the resolved anthropic version in CI moved after that date. Sounds like main needs a pin or an import update; I'll rebase once it lands.

@rubenmarcus

Copy link
Copy Markdown
Author

The import fix landed as #6076, so I rebased: 11a3ef8 merges main at a71d547. All three checks are clean locally on the new head: pyright reports 0 errors, pre-commit run --all-files passes every hook, and pytest tests/ci/integrations/test_anthropic_browser_use.py tests/ci/models/test_llm_schema_optimizer.py gives 15 passed, 1 skipped. The full tests/ci/models/ slice: 123 passed, 7 skipped.

sun04222 added a commit to sun04222/browser-use that referenced this pull request Oct 23, 2026
… schema comment kept ours, test fixtures union)
@mintlify

mintlify Bot commented Nov 1, 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 7809760.

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.

Bug: schema cleanup removes fields named default, minItems, or min_items

2 participants