Schema round trip: carry param descriptions as Annotated metadata; unwrap Annotated in handle_type - #99
Merged
Merged
Conversation
…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
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". |
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.
A schema-derived function should be re-derivable:
get_schemaonmk_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 viamk_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_paramread type/default/required from the wire schema and droppeddescription(aParameterhas no docstring field). It now carries it asAnnotated[T, desc], whichdocmentsalready reads.handle_typenever unwrappedAnnotated, so anyAnnotatedparameter produced a junk type likeobject[number, object]— a latent bug independent of the round trip. It now unwraps viaann_partsbefore 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; fullnbdev-testpasses.Cost worth noting:
str(inspect.signature(...))on rebuilt tools now shows theAnnotatedwrapper. AnswerDotAI/mcpmini has a one-test companion PR updating its byte-exact signature assertion to assert the round-trip property instead.