GPT generates random function parameters

Hey!

I’ve been dealing with a situation, where GPT decides to generate a random function parameter, in order to execute a certain function. (At the moment, using GPT 4 0125 model)

Here is a mock of one of the functions, to have it as an example:

@meta(
    name="sell_domain",
    description="This function gives information, on how to sell a specific user's domain. ",
    parameters={
        "type": "object",
        "properties": {
            "domain_name": {
                "type": "string",
                "description": "user's given domain name. This domain must be taken from user's input.",
            }
        },
        "required": ["domain_name"],
    },
)

As you may see, this function expects to receive a domain_url from the user’s input.

Now let’s imagine, that in the function, I am doing certain checks, to see, where the domain is purchased from, in order to personalize the steps, so they would match exactly what the user needs to do, rather than giving general information.

Usually (70% of the cases), GPT doesn’t call this function, without knowing the user’s domain name, although, in the rest of the cases, GPT decides to give a random domain name, because the user hasn’t mentioned any in his message. GPT doesn’t try to clarify with the user, and instead, provides a parameter like: “example_com”, “domainexample_org”, “non-existing-domain_net”…, etc. (had to change dots to underscores, since this form doesn’t allow links) Basically, a domain name, as an example, which in general, is still a valid domain, that cannot be re-verified by some regex.

For example, the user’s input could be: “Hey, I’d like to sell my domain”

Since the domain is still valid, my checks are going through, I locate where the domain is purchased, and I provide steps for that exact domain. GPT takes that response as truth, and simply provides these steps to the user, which leads to a bad experience because the steps are far from being correct since the user has the domain purchased somewhere else.

So far, I’ve been trying to deal with this issue in these ways:

  • Better prompt - one of the main things, that helps to reduce this random domain generation, but still, not even close to it being perfect, GPT still decides to call this function, without having required slots filled by the user. No matter how extensively I say in system/function descriptions, that you must clarify with the user about his domain name, you cannot generate random domain names…
  • Removing the “required” slot from the meta, so GPT instead gives an empty string/doesn’t provide a domain at all, as a parameter. Then simply defaulting the domain_name param in the function to None, and doing a simple if check, returning the message, that it’s required to have a domain name from the user’s input.
  • Having a list of most commonly randomly generated domains by GPT, validating against it, and returning if GPT generated a domain, I expect to be random. This is a workaround, rather than a solution, as GPT still generates some sort of random domain, that I haven’t added to this list.

Even after these multiple workarounds, I still face an issue, where GPT generates me most random domain ever, causing incorrect answers generated by the function. It feels like GPT simply wants to use the function, without expecting to get the answer that will solve the user’s issue.

Maybe you have faced anything similar in any context, and have any solutions for it? Maybe you have any bullet-proof prompts that work for such cases? Maybe there are some other solutions, that are similar to my mentioned one about removing the required field?

Any ideas are appreciated, as this has been a headache for a long time.

Hey there,

I’m not sure I understand the exact problem (or problems?), can you please provide more concrete examples- the chat messages, the input, what is being executed, and what you expect?

From what I understand, in at least some of the cases, the model calls the function without a domain name being provided at all (?). For this case, I can refer you to the official cookbook on How to call functions with chat models, in which they add a system message saying this:

Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.

In my experience, adding this system message can help.

Another thing I’d recommend is keeping the function’s (and its parameters’) description strictly about what the function does, without referring to the meta of the model: basically changing domain_name parameter’s description from user's given domain name. This domain must be taken from user's input. to something like the domain name to sell.

Hey @ramn7 ,

The issue is in regards to randomly generated domain names that are used as parameters in such function. Here is the example of conversation:

[
        {
            "role": "user",
            "content": "How to sell my domain?"
        },
        {
            "role": "assistant",
            "tool_calls": [
                {
                    "id": "call_fQssSEh8OxvES4iKI0z2ukJa",
                    "type": "function",
                    "function": {
                        "arguments": "{\"domain_name\":\"example.com\"}",
                        "name": "sell_domain"
                    }
                }
            ]
        },
        {
            "role": "tool",
            "tool_call_id": "call_fQssSEh8OxvES4iKI0z2ukJa",
            "content": "specific sell domain steps for domain example.com, in domain provider X. Do 1,2,3.."
        },
        {
            "role": "assistant",
            "content": "Here are the steps how to sell your domain...."
        }
    ]

As you may see, GPT generated that random example.com domain parameter, rather than clarifying with the user. There Is no actual way, to validate it in code as well, as these invalid domains are always random + it would be a workaround. Keep in mind, this example is made very simplistic, to actual real case scenarios, but it displays the actual issue, with randomly generated parameters. This can be for anything, email_address, living_address, todays_date, etc.

In the initial message, I mentioned, that I have tried playing with prompts, etc, but can’t find some sort of semi-bullet proof solution, so GPT would never ever generate random parameters.

Also, tried playing with the prompt like you’ve mentioned:

the domain name to sell .

But usually, GPT just gets too much freedom and avoids clarifying with the user. All in all, this happens like 10-20% of the cases, not always. It’s just a bit too random…

Cool thanks for clarifying.
That’s about what I understood, did you try adding the system message as mentioned? That will look something like this:

[
        {
            "role": "system",
            "content": "Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."
        },
        {
            "role": "user",
            "content": "How to sell my domain?"
        },
...
]

As mentioned, this suggestion is from OpenAI’s cookbook and in my experience often helps, however I’m afraid it’s possible there might be a completely “bulletproof” solution.
I’d try to play with the prompt and see what comes to something you’d find suitable.

BTW- I can recommend Promptotype, which is a tool I’ve created for developing this kind of prompts. It’s basically an extended playground where you can define inputs with their expected outputs, and test your prompts on whole collections at once.
In your case, you can probably defined both “clarification required” cases (in which the function should not be called), and cases when you do expect it- and verify your prompt adjustments handle them correctly.

Will try it out, and will let you know of the results.

Thanks a lot!

1 Like