fix: resolve \$defs/\$ref in tool schemas for HuggingFace API#10705
Open
Br1an67 wants to merge 2 commits intodeepset-ai:mainfrom
Open
fix: resolve \$defs/\$ref in tool schemas for HuggingFace API#10705Br1an67 wants to merge 2 commits intodeepset-ai:mainfrom
Br1an67 wants to merge 2 commits intodeepset-ai:mainfrom
Conversation
The HuggingFace API does not support $defs and $ref in tool parameter schemas. Add _resolve_schema_refs() to inline all $ref pointers and remove the $defs section before sending tool schemas to the API.
|
@Br1an67 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Hi @Br1an67, this PR looks in principle good, but some checks are still failing. I recommend going through out contributing guidelines to fix them. |
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.
Related Issues
$defsfield in tool parameter schema #9387Proposed Changes:
The HuggingFace API does not support
$defsand$refin tool parameter schemas. When tools have complex/dataclass parameters (e.g.ChatMessage,Document), Pydantic'smodel_json_schema()generates schemas with$defssection and$refreferences, which causes failures with the HF API.Added
_resolve_schema_refs()tohugging_face_api.pythat:$defsdefinitions from the schema$refpointers by inlining the definitions$defssection from the final schemaThis function is called in
_convert_tools_to_hfapi_tools()before passing tool parameters to the HF API, following the same pattern used in the Google GenAI integration (PR haystack-core-integrations#1875).No external dependencies are needed — the resolver is a pure Python implementation, avoiding the need to make
jsonrefa core dependency.How did you test it?
Added 4 unit tests:
test_resolve_schema_refs_no_defs— schema without$defspasses through unchangedtest_resolve_schema_refs_expands_defs— basic$defs/$refexpansiontest_resolve_schema_refs_nested_refs— nested$refwithin$defsdefinitionstest_convert_tools_to_hfapi_tools_resolves_defs— end-to-end test through the tool conversion pipelineAll 43 existing non-async tests continue to pass.
Notes for the reviewer
jsonref.replace_refs(), this uses an inline implementation to avoid addingjsonrefas a core dependency (it's currently only an optional dep for OpenAPI components)Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.