Invalid function calling output

Hey,
I’ve been exploring your models and experimenting with function calling, but I’m encountering an issue. My example keeps returning “Invalid function calling output” errors from the API.

my example request body to your service API

{
  "messages": [
    {
      "role": "system",
      "content": "Your answer should be in the same language as the initial query.\nThink step by step.\nDo not call a tool if the input depends on another tool output you dont have yet.\nDo not try to answer until you get tools output, if you dont have an answer yet you can continue calling tools until you do.\nYour answer should be in the same language as the initial query.\nYou are a helpful assistant.\n"
    },
    {
      "role": "user",
      "content": "What is the weather in LA?"
    },
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_d3494f7a409c4a9aa7",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"location\":\"LA\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "content": "It's 25 degrees Celcius and sunny.",
      "name": "get_weather",
      "tool_call_id": "call_d3494f7a409c4a9aa7"
    },
    {
      "role": "system",
      "content": "Please respond conversationally to the user"
    },
    {
      "role": "assistant",
      "content": "The weather in LA is 25 degrees Celcius and sunny."
    },
    {
      "role": "user",
      "content": "what about NY?"
    }
  ],
  "model": "Meta-Llama-3.1-405B-Instruct",
  "temperature": 0.2,
  "max_tokens": 200,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "n": 1,
  "stream": false,
  "tool_choice": "auto",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather in a given location.",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string"
            }
          },
          "required": [
            "location"
          ],
          "additionalProperties": false,
          "$schema": "http://json-schema.org/draft-07/schema#"
        }
      }
    }
  ]
}

gives 200 error response

{
  "error": {
    "code": null,
    "message": "ModelMetaclass object argument after ** must be a mapping, not str",
    "model_output": "{\"name\": \"get_weather\", \"parameters\": \"{\\\"location\\\": \\\"NY\\\"}\"}",
    "param": null,
    "type": "Invalid function calling output."
  }
}

Hope you can help me.
Thanks

1 Like

Hello,

Thank you for bringing this to our attention. We are currently looking into the issue you’re experiencing and will get back to you with an update as soon as possible.

We appreciate your patience in the meantime!

Best regards,
Prajwal.

2 Likes

Hi @razzrazz, Could you please kindly re-confirm whether the function output is being accurately passed to the subsequent function call for further processing?
Here is the example:

Thanks & Regards

hey,
I provided a full body I’m sending to the API service via Postman, so I believe a problem is that request is not processed correctly.
The same problem occurs using OpenAi sdk with langgraph library.

Edit:
looks like API is not able to handle following message

    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_d3494f7a409c4a9aa7",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"location\":\"LA\"}"
          }
        }
      ]
    },

without this part in my request I receive a valid choices[0].message related to another function call output in response, but is this desired behaviour?

Edit2: I think I may narrow down a core issue, I reckon the problem is that OpenAi compatible api returns choices[].message.tool_calls[].function.arguments as JSON strings, but expect parsed value in messages input body.

Changing from JSON string "arguments": "{\"location\":\"LA\"}" to parsed value "arguments": { location: "LA" } does not raise errors.

1 Like

A Jira ticket has been created to address this, and our engineering team is actively working on a resolution. As an interim measure, we ensure that the arguments string is always parsed into a JSON object before being reused in the API’s messages body to prevent errors.
Thanks and Regards

1 Like