Have several mandatory parameters in its function

Good morning,

I created a assistant which must call a function in order to retrieve data from a film via the IMDB API. The function needs two parameters: the movie name and the year the movie was released. When I give the assistant a movie name, it calls the function without asking me its year. How to correct this?

         {
              "name"       : "get_data_movie",
              "description": "retrieve information from a movie",
              "parameters" : {
                  "type"      : "object",
                  "properties": {
                      "title": {
                          "type": "string",
                          "description": "The name of the movie"
                      },
                      "year" : {
                          "type"  : "string",
                          "description": "year of movie release",
                          "format": "year"
                      }
                  },
                  "required"  : ["title", "year"]
              }
          }

THANKS

The quick answer is that by adding the following prompt as part of function’s “description”, I have gotten the system to always submit all parameters:

ALWAYS respond with values for all parameters in this tool.

The longer answer is that the system itself can help you fix this in the future. Whenever the system makes these mistakes I have found that sending a prompt like the following start giving me solutions, even if it takes a few iterations to get right.

You called the get_data_movie function by only submitting the movie’s title, but not the year it was released. How can I change the function description to avoid this mistake in the future?

agree with @sdelgado - you can simply RETURN the error message in words from your get_data_movie() function as well something like {“error”:“No year provided try again with both year and title”}
This will result in another tool_call.
Also in the function description you can be more descriptive - ‘find movie information based on title and year. Both title and year are mandatory’

@jlvanhulst’s idea of adding an error message in the return is great! OpenAI’s model is hopefully smart enough to retry with the right parameters. @graine.de.zele, if you would like to add a “best-practice” tag to this thread, I think it would be a useful reference for people in the future.

From what I understand, it sent a random movie year?

Maybe because the description says year of movie release, maybe you can write

year of movie release as given by the user

@cdonvd0s , @jlvanhulst, sdelgado Thank you for your responses, but unfortunately, I have already tried all of that without success:

The idea of adding an error message in the return does not work because the assistant chooses the year itself. It’s a strange behavior because if I ask for information about a movie that has had several versions, it itself sends a year as a parameter.
I also tried modifying the description that you advised me: “year of movie release as given by the user” But this has no impact, the assistant continues to provide the year itself.

I tried insisting in different ways to make the assistant understand that it must obtain both parameters from the client to call the function, but it only asks for the name of the movie and always makes up the year.

image

Description for the assistant :

Your goal is to provide information about movies. Your information must come only from the “get_data_movie” function. This function needs two mandatory parameters: the name of the movie and the year of the movie. IMPORTANT: You must always obtain these two pieces of data from the user to call the “get_data_movie” function. You must not choose the year of the movie yourself.

{
  "name": "get_data_movie",
  "parameters": {
    "type": "object",
    "properties": {
      "title": {
        "type": "string",
        "description": "The name of the movie"
      },
      "year": {
        "type": "string",
        "description": "year of movie release as given by the user",
        "format": "year"
      }
    },
    "required": [
      "title",
      "year"
    ]
  },
  "description": "Recover movie data"
}

I don’t know what else to try…

This seems to be working fine. It did ask for the year.

It seems to be working fine with GPT-3.5-Turbo (Which I didn’t expect)

I am surprised you don’t get an error for the ‘format’ : “year” because I don’t think that is correct.
What I am also wondering - are you actually returning an ‘error mesage’ - need to provide year when it calls the function with the year?

Yes, Even I just noticed it. I never tried changing any other things apart from descriptions.

Maybe it doesn’t care if the format is year as it’s an LLM.

Can you rephrase to help me understand better?

Well the function format is checked for errors these days - and things like ‘type’ are certainly checked. One thing I would change in the function desccription is 'retrieve movie data by providing title and year, both are mandatory.

And what I meant is - IF gpt calls the function without the year - what do you RETURN - it should be something like {“Description”: “Error you must provide the year of the movie as well”} - that will tell it to ask for the year and try again.

I just copied your prompt and your function call in the playground. No changes at all. I was trying to reproduce it at my end.

I put the same prompt as you and the assistant does not ask me the year. Yet we have the same assistant with the same descriptions and the same function. I do not understand anything anymore…

GPT never calls the function without the year since it is it which invents the year. It is therefore impossible to generate an error. To generate an error GPT would have to call the function without providing the year but it provided it to the function without asking the user

I just did a trial run for you, with gpt-4 turbo with this prompt:

:You are a movie database - you provide information about movies by looking up data with the get_data_movie function. You cannot rely on any other information for the input of this function. The user has to provide both title and year before you can submit information to get_data_mvoie. Do not ‘invent’ the year if the user did not provide it"

And I removed 'format" in the function.

1 Like

I made the changes you recommended but unfortunately it didn’t change anything. GPT still refuses to ask me the year, he prefers to choose it himself…

In my screenshot you can see that GPT chose to send the year 1995 without me giving it this information.

I don’t understand why @cdonvd0s behaves differently from mine

{
  "name": "get_data_movie",
  "description": "Recover movie data",
  "parameters": {
    "type": "object",
    "properties": {
      "title": {
        "type": "string",
        "description": "The name of the movie"
      },
      "year": {
        "type": "string",
        "description": "year of movie release as given by the user"
      }
    },
    "required": [
      "title",
      "year"
    ]
  }
}

It’s good, it works!!! I did all my tests on the same thread, I think I need to run a new thread to be sure that GPT takes the modifications into account. Thank you very much for taking the time to help me!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.