Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Function call exception in some llms #18230

Closed
wangligen1995 opened this issue Mar 22, 2025 · 1 comment · Fixed by #18352
Closed

[Bug]: Function call exception in some llms #18230

wangligen1995 opened this issue Mar 22, 2025 · 1 comment · Fixed by #18352
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@wangligen1995
Copy link

Bug Description

llama_index.core.workflow.errors.WorkflowRuntimeError: Error in step 'run_agent_step': the JSON object must be str, bytes or bytearray, not NoneType

the function not need arguments,gpt-4o return is ''(empty string),some llms return None,When this happens, the workflow ends abnormally.
Although exception is used here, but the err is json.JSONDecodeError not ValueError

filepath:https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/base.py

Image Image

Version

0.12.23

Steps to Reproduce

this demo
https://github.com/run-llama/python-agents-tutorial/blob/main/6_multi_agent.py
with other llms

Relevant Logs/Tracbacks

@wangligen1995 wangligen1995 added bug Something isn't working triage Issue needs to be triaged/prioritized labels Mar 22, 2025
Copy link

dosubot bot commented Mar 22, 2025

@wangligen1995 Greetings! I'm here to help you with any bugs, questions, or contributions.

I found a similar issue that was previously reported and resolved. The issue was titled "[Bug]: SlackToolSpec.get_fn_schema_from_fn_name needs to return a schema" and was closed by a pull request that fixed the "fn_schema is None" issue [1].

To address the current issue you're facing with NoneType responses leading to a WorkflowRuntimeError, you can adjust the error handling in the base.py file of the llama_index library. Specifically, you can modify the _parse_tool method to check for None before attempting to parse the JSON. Here's a suggested modification:

def _parse_tool(self, tool_call: ToolCall) -> ToolSelection:
    if not isinstance(tool_call, ToolCall):
        raise ValueError("Invalid tool_call object")

    if tool_call.type != "function":
        raise ValueError(f"Unsupported tool call type: {tool_call.type}")

    # Check if tool_call.function.arguments is None
    if tool_call.function.arguments is None:
        argument_dict = {}
    else:
        try:
            argument_dict = parse_partial_json(tool_call.function.arguments)
        except ValueError:
            argument_dict = {}

    return ToolSelection(
        tool_id=tool_call.id,
        tool_name=tool_call.function.name,
        tool_kwargs=argument_dict,
    )

This change ensures that if tool_call.function.arguments is None, it initializes argument_dict as an empty dictionary, thus preventing any NoneType related errors during JSON parsing [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant