crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] resolve_refs drops the description and other keys next to a $ref

Open surlymochan opened this issue 1 month ago • 2 comments

Description

resolve_refs in crewai/utilities/pydantic_schema_utils.py replaces a $ref node with the referenced definition and drops every other key on that node. Pydantic puts field-level metadata next to the $ref ({"$ref": "#/$defs/Leaf", "description": "the leaf"}), so a nested model field loses its description (and default, title) after resolution. generate_model_description goes through resolve_refs, so the schema sent to the LLM for output_pydantic / structured output shows the nested model's docstring instead of the field description, or no description at all.

Steps to Reproduce

from pydantic import BaseModel, Field
from crewai.utilities.pydantic_schema_utils import resolve_refs

class Leaf(BaseModel):
    """A leaf model."""
    value: int

class Holder(BaseModel):
    nested: Leaf = Field(description="the leaf")

raw = Holder.model_json_schema()
print(raw["properties"]["nested"])                 # {'$ref': '#/$defs/Leaf', 'description': 'the leaf'}
print(resolve_refs(raw)["properties"]["nested"]["description"])   # 'A leaf model.'

Expected behavior

Keys next to $ref are kept and take precedence over the definition's keys, so nested resolves to the Leaf schema with description: "the leaf".

Screenshots/Code snippets

See the snippet above. Current main (40bb2d3), pydantic 2.12.5.

Operating System

Ubuntu 24.04

Python Version

3.13

crewAI Version

1.15.28 (main)

surlymochan avatar Oct 18 '26 06:10 surlymochan

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 17 '26 12:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 23 '26 12:11 github-actions[bot]