Skip to content

fix: propagate parameter descriptions in create_tool_call#472

Merged
jjovalle99 merged 1 commit intomainfrom
fix/create-tool-call-descriptions
Apr 4, 2026
Merged

fix: propagate parameter descriptions in create_tool_call#472
jjovalle99 merged 1 commit intomainfrom
fix/create-tool-call-descriptions

Conversation

@jjovalle99
Copy link
Copy Markdown
Contributor

@jjovalle99 jjovalle99 commented Apr 4, 2026

Summary

  • _get_function_parameters mutates field_info.description after FieldInfo
    construction (line 137). Pydantic v2 ignores this mutation in
    model_json_schema() because it only reads attributes passed at Field()
    construction time. Pydantic documents this as "only accidentally working"
    since _attributes_set is not updated. All docstring-derived parameter
    descriptions are silently dropped from the generated tool schema.
  • For fresh FieldInfos (no existing annotation), pass description= directly
    to Field() at construction.
  • For existing FieldInfos (from Annotated[T, Field(...)] or = Field(...)
    defaults), override description via Annotated stacking. Pydantic merges
    stacked metadata left-to-right
    ,
    so the description Field appended last takes precedence while preserving
    existing constraints. This is the same pattern Pydantic uses in
    rebuild_annotation().
    No private APIs.

Fixes #471

Test plan

  • 17 new tests in src/mistralai/extra/tests/test_tools.py
  • Covers: docstring descriptions, Annotated with constraints, Field-as-default,
    shared FieldInfo instances, required vs optional params, no-docstring edge cases
  • 10 of 17 fail on current main, 17/17 pass with this fix

_get_function_parameters mutates field_info.description after FieldInfo
construction. Pydantic v2 ignores this because _attributes_set is not
updated. All docstring-derived parameter descriptions are silently
dropped from the generated tool schema.

For fresh FieldInfos, pass description to Field() at construction.
For existing FieldInfos, override via Annotated stacking (public API).
@jjovalle99 jjovalle99 merged commit c9c1b31 into main Apr 4, 2026
6 checks passed
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 CLIENT]: create_tool_call silently drops parameter descriptions from JSON schema

2 participants