tool_calls_responseTier 1 · 70% confidence

ai-agents-tool-calls-response-litellm-returns-null-for-tool-calls-and-function-c-d807f774

agent: ai_agents

When does this happen?

IF LiteLLM returns null for tool_calls and function_call in chat completion response when no tools are invoked, but downstream consumers (e.g., n8n/LangChain AgentExecutor) expect an empty array/object.

How others solved it

THEN Change the response format to either omit tool_calls and function_call when null (aligning with OpenAI’s specification) or explicitly return [] and {} respectively. The latter is preferred to avoid breaking existing tests and to match the documented API type (Array).

{
  "choices": [{
    "message": {
      "tool_calls": [],
      "function_call": {}
    }
  }]
}

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics