Skip to content

Schema round trip: carry param descriptions as Annotated metadata; unwrap Annotated in handle_type - #99

Merged
jph00 merged 1 commit into
mainfrom
roundtrip-schema
Aug 3, 2026
Merged

Schema round trip: carry param descriptions as Annotated metadata; unwrap Annotated in handle_type#99
jph00 merged 1 commit into
mainfrom
roundtrip-schema

Conversation

@erikgaas

@erikgaas erikgaas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

A schema-derived function should be re-derivable: get_schema on mk_tool's output reproduces the schema it was built from. Today parameter descriptions are lost in the rebuild — noticed because an MCP client's bound tools (mcpmini rebuilds them via mk_tool) re-enter fastllm with empty param descriptions, which is exactly what a model reads when deciding what to pass.

Two defects, both fixed here:

  • mk_param read type/default/required from the wire schema and dropped description (a Parameter has no docstring field). It now carries it as Annotated[T, desc], which docments already reads.
  • handle_type never unwrapped Annotated, so any Annotated parameter produced a junk type like object[number, object] — a latent bug independent of the round trip. It now unwraps via ann_parts before type mapping, so unions/lists/nested types all see the bare type.

New test asserts the whole round trip (get_schema(mk_tool(noop, t)) == t), red before the fix, green after; full nbdev-test passes.

Cost worth noting: str(inspect.signature(...)) on rebuilt tools now shows the Annotated wrapper. AnswerDotAI/mcpmini has a one-test companion PR updating its byte-exact signature assertion to assert the round-trip property instead.

…ated metadata

get_schema on mk_tool's output now reproduces the schema it was built from.
Two fixes: mk_param writes the wire description into the annotation as
Annotated[T, desc] (which docments already reads), and handle_type unwraps
Annotated before type mapping (previously any Annotated param produced a
junk type like 'object[number, object]').

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHkskFwAKk5LNW4xMpeZFP
@erikgaas
erikgaas requested a review from jph00 August 3, 2026 03:12
@jph00
jph00 merged commit 473c9e2 into main Aug 3, 2026
@jph00 jph00 added the bug Something isn't working label Aug 3, 2026
@jph00

jph00 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks @erikgaas . BTW please trim down your PR text to just what I really need to know. Verbose AI outputs take a long time to read and understand! E.g "Cost worth noting: str(inspect.signature(...)) on rebuilt tools now shows the Annotated wrapper" is classic Claude nonsense. There's no situation where anyone could possibly care about that AFAICT. Ditto for nearly every part of "New test asserts the whole round trip (get_schema(mk_tool(noop, t)) == t), red before the fix, green after; full nbdev-test passes".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants