Repository navigation
Conversation
get_schema_from_signature treated *args and **kwargs parameters like regular keyword arguments, so they became required properties of the generated JSON Schema. Such parameters can never be bound via ** unpacking: passing a schema-valid object then raises "TypeError: got an unexpected keyword argument" when the function has no **kwargs to absorb them, and otherwise the values silently land in **kwargs under their own names. Skip parameters whose kind is VAR_POSITIONAL or VAR_KEYWORD, so every JSON object valid to the schema can be passed to the function with **, as the docstring promises.
This branch has not been deployed
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.
Summary
get_schema_from_signaturenow skips*argsand**kwargsparameters instead of turning them into schema properties.Why
get_schema_from_signaturebuilt a Pydantic model from every parameter in the signature, including the var-positional (*args) and var-keyword (**kwargs) ones (src/outlines/types/utils.py:199). Since such parameters have no default, they became required properties of the generated schema, even though they can never be bound by**unpacking. This violates the invariant documented in the docstring (src/outlines/types/utils.py:193): every JSON object valid to the output schema must be passable to the function with**:When the function does have a
**kwargsparameter to absorb them, the values silently land in**kwargsunder their own names instead of the variadic parameters they represent.Changes
src/outlines/types/utils.py: skip parameters whose kind isVAR_POSITIONALorVAR_KEYWORDinget_schema_from_signature.tests/types/test_types_utils.py: regression testtest_get_schema_from_signature_ignores_var_parameters.Testing