Repository navigation
fix(helpers): do not include $schema in description in transform_schema - #2057
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an input schema provided to
transform_schemacontains the standard$schemadialect identifier keyword (common in schemas emitted by JSON Schema generators, Pydantic, or manually specified draft-07 / 2020-12 schemas),transform_schemadoes not strip it.Because
$schemais not recognized as one of the supported strict schema properties, it is treated as an extra property and appended intostrict_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
src/anthropic/lib/_parse/_transform.py, pop and drop"$schema"alongside$defsand$ref.tests/lib/_parse/test_transform.py:test_schema_keyword_droppedverifying$schemais omitted without generating a corrupted description.test_schema_keyword_dropped_with_existing_descriptionensuring user descriptions are preserved cleanly without dialect metadata.test_schema_keyword_with_refconfirming schemas containing both$schemaand$refresolve properly.Verification
uv run pytest tests/lib/_parse/test_transform.py(17/17 passed).uv run ruff check&uv run ruff format --check(clean).uv run pyright(0 errors, 0 warnings).