# Invalid function calling output

**URL:** <https://community.sambanova.ai/t/invalid-function-calling-output/791>\
**Category:** SambaNova Devs\
**Tags:** jira-issue\
**Created:** [January 6, 2025, 12:19pm UTC](https://community.sambanova.ai/t/invalid-function-calling-output/791 "2025-01-06T12:19:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![razzrazz](https://sea1.discourse-cdn.com/sambanova/user_avatar/community.sambanova.ai/razzrazz/32/1594_2.png) [@razzrazz](https://community.sambanova.ai/u/razzrazz)\
**Post date:** [January 6, 2025, 12:19pm UTC](https://community.sambanova.ai/t/invalid-function-calling-output/791/1 "2025-01-06T12:19:15Z")

</div>

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

```auto
{
  "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

```auto
{
  "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

---

<div class="post-metadata">

**Author:** ![prajwal.balapure](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@prajwal.balapure](https://community.sambanova.ai/u/prajwal.balapure)\
**Post date:** [January 6, 2025, 12:27pm UTC](https://community.sambanova.ai/t/invalid-function-calling-output/791/2 "2025-01-06T12:27:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![omkar.gangan](https://sea1.discourse-cdn.com/sambanova/user_avatar/community.sambanova.ai/omkar.gangan/32/217_2.png) [@omkar.gangan](https://community.sambanova.ai/u/omkar.gangan)\
**Post date:** [January 6, 2025, 1:22pm UTC](https://community.sambanova.ai/t/invalid-function-calling-output/791/3 "2025-01-06T13:22:23Z")

</div>

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:

> [@Function Calling and JSON mode in SambaNova Cloud](https://community.sambanova.ai/t/function-calling-and-json-mode-in-sambanova-cloud/540/1):
>
> ### Step 4: Provide Function Results Back to the Model
> 
> Once you have computed the result, pass it back to the model to continue the conversation or confirm the output.

Thanks & Regards

---

<div class="post-metadata">

**Author:** ![razzrazz](https://sea1.discourse-cdn.com/sambanova/user_avatar/community.sambanova.ai/razzrazz/32/1594_2.png) [@razzrazz](https://community.sambanova.ai/u/razzrazz)\
**Post date:** [January 6, 2025, 1:52pm UTC](https://community.sambanova.ai/t/invalid-function-calling-output/791/4 "2025-01-06T13:52:58Z")

</div>

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

```auto
    {
      "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.

---

<div class="post-metadata">

**Author:** ![omkar.gangan](https://sea1.discourse-cdn.com/sambanova/user_avatar/community.sambanova.ai/omkar.gangan/32/217_2.png) [@omkar.gangan](https://community.sambanova.ai/u/omkar.gangan)\
**Post date:** [January 7, 2025, 7:22am UTC](https://community.sambanova.ai/t/invalid-function-calling-output/791/5 "2025-01-07T07:22:40Z")

</div>

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
