transform_schema drops description beside $ref, which the API accepts and follows

Ouverte
#2,016 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

@Parsiffall1 y travaille déjà.

Depuis le 11/10/2026.

  • #2017 par @Parsiffall1 — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
python
Domaine
api, backend

Piste de recherche

Start by reading transform_schema and the tests for schema transformation in the Python SDK; the issue does not name their paths. Reproduce the example with Answer.model_json_schema() and compare the transformed property. Done when the description beside $ref is retained, with a regression test covering a Pydantic enum or model field. An open linked pull request (#2017) is already addressing this issue.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

When a property has a $ref, transform_schema returns {"$ref": ...} alone and drops the keywords beside it, including description. Pydantic puts a field's Field(description=...) beside the $ref whenever the field's type is an enum or a model, so those descriptions never reach Claude when a model goes through transform_schema.

from enum import Enum
from pydantic import BaseModel, Field
from anthropic import transform_schema

class Level(str, Enum):
    high = "high"
    low = "low"

class Answer(BaseModel):
    level: Level = Field(description="Always choose low.")

Answer.model_json_schema()["properties"]["level"]
# {'$ref': '#/$defs/Level', 'description': 'Always choose low.'}
transform_schema(Answer)["properties"]["level"]
# {'$ref': '#/$defs/Level'}

The API accepts the description there and the model follows it. Sending the pydantic schema above (with additionalProperties: false) directly as output_config={"format": {"type": "json_schema", "schema": ...}} to claude-haiku-5-5, with the prompt "Rate your confidence that 2+2=4.", returned {"level":"low"}.

Expected: transform_schema keeps description beside $ref. A workaround is to put the text in the enum's docstring, which becomes the $defs entry's description.

anthropic 1.13.0, pydantic 2.14.0. Related: #1817, #1764. Found and reproduced with Claude Code.

Langage dominant
Python
Étoiles
4.1k
Forks
915
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de anthropics/anthropic-sdk-python

Toutes les issues de anthropics/anthropic-sdk-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.