Skip to content

fix(helpers): do not include $schema in description in transform_schema - #2057

Open
reginaldalfret wants to merge 1 commit into
anthropics:mainfrom
reginaldalfret:fix/transform-schema-drop-schema-key
Open

reginaldalfret wants to merge 1 commit into
anthropics:mainfrom
reginaldalfret:fix/transform-schema-drop-schema-key

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

When an input schema provided to transform_schema contains the standard $schema dialect identifier keyword (common in schemas emitted by JSON Schema generators, Pydantic, or manually specified draft-07 / 2020-12 schemas), transform_schema does not strip it.

Because $schema is not recognized as one of the supported strict schema properties, it is treated as an extra property and appended into strict_schema["description"] (e.g., {$schema: https://json-schema.org/draft/2020-12/schema}). This pollutes the description presented to Claude with internal schema dialect metadata.

Changes

  • In src/anthropic/lib/_parse/_transform.py, pop and drop "$schema" alongside $defs and $ref.
  • Added regression tests in tests/lib/_parse/test_transform.py:
    • test_schema_keyword_dropped verifying $schema is omitted without generating a corrupted description.
    • test_schema_keyword_dropped_with_existing_description ensuring user descriptions are preserved cleanly without dialect metadata.
    • test_schema_keyword_with_ref confirming schemas containing both $schema and $ref resolve properly.

Verification

  • Ran test suite: uv run pytest tests/lib/_parse/test_transform.py (17/17 passed).
  • Lint and formatting: uv run ruff check & uv run ruff format --check (clean).
  • Type checking: uv run pyright (0 errors, 0 warnings).

When an input JSON schema contains the standard `$schema` dialect identifier keyword (e.g. from draft-07, draft 2020-12, or schemas emitted by generator libraries), `transform_schema` does not strip it. Because it is not recognized as a supported strict schema property, it is retained in the leftover properties and serialized into `strict_schema["description"]` (e.g. `{$schema: https://...}`), corrupting the description provided to Claude.

This change pops and discards `$schema` from the input dictionary, matching the handling in the TypeScript SDK.

Signed-off-by: Reginald Alfret <reginaldalfret@gmail.com>
@reginaldalfret
reginaldalfret requested a review from a team as a code owner November 3, 2026 19:19
@reginaldalfret reginaldalfret changed the title fix(helpers): do not include `$schema in description in transform_schema fix(helpers): do not include $schema in description in transform_schema Nov 3, 2026

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.

1 participant