litellm - ✅(Solved) Fix [Bug]: LiteLLM parsing/compatibility bug with claude-sonnet-4.6 model for GitHub Copilot provider [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24565Fetched 2026-04-08 01:27:03
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×2labeled ×2subscribed ×2

Error Message

{ "role": "user", "content": "Tool call error:\n\n<error>\nNo tool calls found in the response. Every response MUST include at least one tool call.\n</error>\n\nHere is general guidance on how to submit correct toolcalls:\n\nEvery response needs to use the 'bash' tool at least once to execute commands.\n\nCall the bash tool with your command as the argument:\n- Tool: bash\n- Arguments: {"command": "your_command_here"}\n\nIf you want to end the task, please issue the following command: echo COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT\nwithout any other command.", "extra": { "interrupt_type": "FormatError" } },

PR fix notes

PR #805: Handle tool calls split across chat choices

Description (problem / solution / changelog)

Fixes #804

Summary

This PR fixes tool-call parsing when a chat-completions provider returns assistant text and tool calls in separate choices within the same response.

mini-swe-agent currently assumes the relevant assistant message is always in response.choices[0]. In practice, some provider integrations can return assistant text in one choice and the tool call in another, which causes tool-call parsing to fail even though a valid tool call was returned.

Changes

  • merge assistant content and tool_calls across returned chat choices before parsing
  • update LitellmModel to read merged message/tool-call data instead of only choices[0]
  • update PortkeyModel similarly for consistency
  • make tool-call parsing accept both object-style and dict-style tool call entries
  • add regression tests for split-choice tool-call responses
  • sanitize task-specific fixture names in tests

Why this helps

This makes tool-call parsing more robust across provider adapters without changing the normal single-choice path.

Verification

I added regression tests covering:

  • assistant text in one choice and tool calls in another
  • dict-style tool calls after message normalization

Reviewer Checklist

  • confirm merging across chat choices is acceptable for tool-call models
  • confirm object-style and dict-style tool-call parsing both look reasonable
  • confirm the added regressions cover the intended response shape without overfitting to one provider

Changed files

  • src/minisweagent/models/litellm_model.py (modified, +3/-2)
  • src/minisweagent/models/portkey_model.py (modified, +3/-2)
  • src/minisweagent/models/utils/actions_toolcall.py (modified, +72/-4)
  • tests/models/test_litellm_model.py (modified, +60/-0)
  • tests/models/test_portkey_model.py (modified, +40/-0)

Code Example

{
      "role": "user",
      "content": "Tool call error:\n\n<error>\nNo tool calls found in the response. Every response MUST include at least one tool call.\n</error>\n\nHere is general guidance on how to submit correct toolcalls:\n\nEvery response needs to use the 'bash' tool at least once to execute commands.\n\nCall the bash tool with your command as the argument:\n- Tool: bash\n- Arguments: {\"command\": \"your_command_here\"}\n\nIf you want to end the task, please issue the following command: `echo COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT`\nwithout any other command.",
      "extra": {
        "interrupt_type": "FormatError"
      }
    },

---

{
  "id": "chatcmpl-DNBTij6z7Z1VfcxaMXOJsvAJHzcTF",
  "choices": [
    {
      "finish_reason": "tool_calls",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": "**************************",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [
          {
            "id": "call_QShR8ENoBVFf0Wq4zjWIHlF1",
            "function": {
              "arguments": "{\"command\":\"find . -name \\\"asd.java\\\"\"}",
              "name": "bash"
            },
            "type": "function"
          }
        ],
        "padding": "abcdefg"
      },
      "content_filter_results": {}
    }
  ],
  "created": null,
  "model": "gpt-4.1-2025-04-14",
  "object": null,
  "service_tier": "default",
  "system_fingerprint": "fp_344891b39a",
  "usage": {
    "completion_tokens": 131,
    "prompt_tokens": 1585,
    "total_tokens": 1716,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": null,
      "reasoning_tokens": null,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens_details": {
      "audio_tokens": null,
      "cached_tokens": 0
    },
    "reasoning_tokens": 0
  }
}

---

{
  "id": "e22cfebb-2f39-46c6-9ae9-49936d537b02",
  "choices": [
    {
      "finish_reason": "tool_calls",
      "index": null,
      "logprobs": null,
      "message": {
        "content": "****",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": null
      }
    },
    {
      "finish_reason": "tool_calls",
      "index": null,
      "logprobs": null,
      "message": {
        "content": null,
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [
          {
            "id": "tooluse_cZxTV6UnDy6kxrvj1ILide",
            "function": {
              "arguments": "{\"command\":\"find . -name \\\"asd.java\\\" -type f\"}",
              "name": "bash"
            },
            "type": "function"
          }
        ]
      }
    }
  ],
  "created": 1774417695,
  "model": "Claude Sonnet 4.6",
  "object": null,
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 96,
    "prompt_tokens": 2342,
    "total_tokens": 2438,
    "completion_tokens_details": null,
    "prompt_tokens_details": {
      "audio_tokens": null,
      "cached_tokens": 0
    }
  }

---
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Hi I am trying to use litellm over mini-swe-agent (https://mini-swe-agent.com/latest/)

I am using GitHub Copilot provider. When i use gpt-4.1 model there is no error.

However when i try to use claude-sonnet-4.6 model i have below error in agent:

   {
      "role": "user",
      "content": "Tool call error:\n\n<error>\nNo tool calls found in the response. Every response MUST include at least one tool call.\n</error>\n\nHere is general guidance on how to submit correct toolcalls:\n\nEvery response needs to use the 'bash' tool at least once to execute commands.\n\nCall the bash tool with your command as the argument:\n- Tool: bash\n- Arguments: {\"command\": \"your_command_here\"}\n\nIf you want to end the task, please issue the following command: `echo COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT`\nwithout any other command.",
      "extra": {
        "interrupt_type": "FormatError"
      }
    },

What i noticed is that for gpt-4.1 model there is a single choice element with both content and toolcalls. But claude is returning two separate choices — one with text content and one with tool calls — instead of a single choice with both.

Response from gpt-4.1 -> Parsed by litellm

{
  "id": "chatcmpl-DNBTij6z7Z1VfcxaMXOJsvAJHzcTF",
  "choices": [
    {
      "finish_reason": "tool_calls",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": "**************************",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [
          {
            "id": "call_QShR8ENoBVFf0Wq4zjWIHlF1",
            "function": {
              "arguments": "{\"command\":\"find . -name \\\"asd.java\\\"\"}",
              "name": "bash"
            },
            "type": "function"
          }
        ],
        "padding": "abcdefg"
      },
      "content_filter_results": {}
    }
  ],
  "created": null,
  "model": "gpt-4.1-2025-04-14",
  "object": null,
  "service_tier": "default",
  "system_fingerprint": "fp_344891b39a",
  "usage": {
    "completion_tokens": 131,
    "prompt_tokens": 1585,
    "total_tokens": 1716,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": null,
      "reasoning_tokens": null,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens_details": {
      "audio_tokens": null,
      "cached_tokens": 0
    },
    "reasoning_tokens": 0
  }
}

Response from claude-sonnet-4.6 -> Not parsed by litellm


{
  "id": "e22cfebb-2f39-46c6-9ae9-49936d537b02",
  "choices": [
    {
      "finish_reason": "tool_calls",
      "index": null,
      "logprobs": null,
      "message": {
        "content": "****",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": null
      }
    },
    {
      "finish_reason": "tool_calls",
      "index": null,
      "logprobs": null,
      "message": {
        "content": null,
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [
          {
            "id": "tooluse_cZxTV6UnDy6kxrvj1ILide",
            "function": {
              "arguments": "{\"command\":\"find . -name \\\"asd.java\\\" -type f\"}",
              "name": "bash"
            },
            "type": "function"
          }
        ]
      }
    }
  ],
  "created": 1774417695,
  "model": "Claude Sonnet 4.6",
  "object": null,
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 96,
    "prompt_tokens": 2342,
    "total_tokens": 2438,
    "completion_tokens_details": null,
    "prompt_tokens_details": {
      "audio_tokens": null,
      "cached_tokens": 0
    }
  }

There seems to be a LiteLLM parsing/compatibility bug with claude-sonnet-4.6 model for GitHub Copilot provider

Steps to Reproduce

  1. Use mini-swe-agent with model_name: "github_copilot/claude-sonnet-4.5"

Relevant log output

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

1.82.4

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To resolve the compatibility issue with the Claude Sonnet 4.6 model, we need to modify the LiteLLM parsing logic to handle responses with separate choices for content and tool calls.

Step 1: Update the Parsing Logic

We will update the parse_response function in the LiteLLM SDK to merge the content and tool calls from separate choices into a single choice.

def parse_response(response):
    # ...
    choices = response.get('choices', [])
    merged_choices = []
    for choice in choices:
        if choice.get('message', {}).get('content') and choice.get('message', {}).get('tool_calls'):
            # Content and tool calls are already merged, add to merged choices
            merged_choices.append(choice)
        elif choice.get('message', {}).get('content'):
            # Content only, add to merged choices with empty tool calls
            merged_choices.append({
                'finish_reason': choice.get('finish_reason'),
                'index': choice.get('index'),
                'logprobs': choice.get('logprobs'),
                'message': {
                    'content': choice.get('message', {}).get('content'),
                    'refusal': choice.get('message', {}).get('refusal'),
                    'role': choice.get('message', {}).get('role'),
                    'annotations': choice.get('message', {}).get('annotations'),
                    'audio': choice.get('message', {}).get('audio'),
                    'function_call': choice.get('message', {}).get('function_call'),
                    'tool_calls': []
                }
            })
        elif choice.get('message', {}).get('tool_calls'):
            # Tool calls only, find the corresponding content choice and merge
            content_choice = next((c for c in choices if c.get('message', {}).get('content')), None)
            if content_choice:
                merged_choice = {
                    'finish_reason': choice.get('finish_reason'),
                    'index': choice.get('index'),
                    'logprobs': choice.get('logprobs'),
                    'message': {
                        'content': content_choice.get('message', {}).get('content'),
                        'refusal': content_choice.get('message', {}).get('refusal'),
                        'role': content_choice.get('message', {}).get('role'),
                        'annotations': content_choice.get('message', {}).get('annotations'),
                        'audio': content_choice.get('message', {}).get('audio'),
                        'function_call': content_choice.get('message', {}).get('function_call'),
                        'tool_calls': choice.get('message', {}).get('tool_calls')
                    }
                }
                merged_choices.append(merged_choice)
    return {'choices': merged_choices}

Step 2: Update the LiteLLM SDK

Update the LiteLLM SDK to use the new parse_response function.

import litellm

def main():
    # ...
    response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING