fix(types): normalise Function.args/kwargs None to [] / {} in __post_init__#484
Open
SuperMarioYL wants to merge 1 commit into
Open
Conversation
…init__
When a JsonOutputParser schema emits "required": [] for Function, LLMs may
omit args or kwargs entirely; the deserialiser then sets those fields to None.
Any subsequent *func.args or **func.kwargs unpack raises TypeError.
Add __post_init__ to Function that converts None → [] for args and None → {}
for kwargs so every call site is safe without per-site guard code.
Fixes SylphAI-Inc#479
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
Fixes #479.
FunctiondeclaresargsandkwargsasOptional[List]/Optional[Dict]withdefault_factory=list/default_factory=dict. The defaults only apply when a field is omitted; an explicitNone(whichJsonOutputParserproduces when the LLM omits or nullifies a field) bypasses the factory and storesNonedirectly. Any subsequent unpack (*func.args,**func.kwargs) then raises:This crash affects every call site that unpacks
func.args/func.kwargs—ToolManager.execute_func,ToolManager.execute_func_async,CallFunctionTool.call, andPermissionManager.Fix
Add
Function.__post_init__(callingsuper().__post_init__()to keep base-class metadata validation) that normalisesNone → []forargsandNone → {}forkwargs. All existing and future call sites are protected without per-site guard code.Tests
Five new tests added to
adalflow/tests/test_tool.py:test_function_none_args_normalised_to_empty_listFunction(args=None)stores[]test_function_none_kwargs_normalised_to_empty_dictFunction(kwargs=None)stores{}test_function_both_none_normalisedNoneat oncetest_function_tool_call_with_none_args_does_not_raisetool.call(*func.args, **func.kwargs)doesn't crashtest_tool_manager_execute_func_with_none_argsToolManager.execute_funcround-tripAll 29 tests in
test_tool.pypass (24 pre-existing + 5 new).