Malformed function-calling arguments

I’m running into a case where the arguments for a single named function are almost always malformed within the API response for function_call.

Example response:

{"name"=>"final_answer", "arguments"=>"\nObservation: The size of your Rails EC2 instance is 't2.large'."}

arguments should be an object with an answer key. Here’s the relevant part of my schema sent in the API request:

{
      "name": "final_answer",
      "description": "Provide me with a final answer to my question.",
      "parameters": {
        "type": "object",
        "properties": {
          "answer": {
            "type": "string",
            "description": "The text you'd like to show to me as your final answer."
          }
        },
        "required": ["answer"]
      }
    }

If I append a message like this, the response seems to self-correct:

{
      "role": "assistant",
      "content": "The last function arguments you returned were malformed."
    }

Anyone else seen this? Again, odd this only happens (so far) with a single function for me.

1 Like

I am experiencing a very high failure rate on returned function call arguments from gpt4. The relevant part of my specification is

response = openai.ChatCompletion.create(
model=self.MODEL,
messages=[{“role”:“system”, “content”:“”"
Use your function calling capability
Your job is to decide which function should be used and to
generate paramaters used by that function to answer the user query.
Do not attempt to answer the query yourself.
Always return arguments for the function call and the function_call key.
“”"
},
{“role”: “user”, “content”: prompt}],
functions=[
{
“name”: “search_selected_email”,
“description”: “Retrieve documents from the database relevant to a query”,
“parameters”: {
“type”: “object”,
“properties”: {
“query”: {
“type”: “string”,
“description”: “”"
an English language question, phrase, or keywords taken from the user prompt
which does not include to and from names or date ranges if specified in the prompt
“”"
},
“Firstday”: {
“type”: “string”,
“description”:“the first day of any specified date range in the format yyyy-mm-dd”
},
“Lastday”: {
“type”: “string”,
“description”:“the last day inclusive of any specified date range in the format yyyy-mm-dd”
},
“From”: {“type”:“string”,
“description”: “a comma delimited list of the last names of people specified in the query who said or wrote something”
},
“To”:{“type”:“string”,
“description”: “a comma delimited list of the last names of people who received or read something”
}
},
“required”: [“query”],
},
}
],
function_call=“auto”,
)

There are both formatting and other errors.Usually the parameters are returned, as they should be, at the same json level as “function_call”, sometimes they are within the ‘function_call’ value two levels down within json objects labeled as either ‘args’ or ‘arguments’. sometimes the whole json string is doubled up. Still other times some arguments which should be there based on the content of the prompt are not. The errors seem to occur most when either to or from is a list of names.

During this testing the prompts are always the same format.

1 Like