GPT3.5 Function Calling - Validate function properties

I am using the function calling API for gpt3.5-turbo.

There is a function which to book an appointment and it accepts the name of the user and the date of the appointment.

It’s working correctly in ideal scenarios. But it’s accepting names with numbers like arun2728 which is incorrect.

Request

{
    "model": "gpt-3.5-turbo-0613",
    "messages": [
        {
            "role": "system",
            "content": "Today is Tuesday, 01th August 2023 11:09 AM."
        },
        {
            "role": "user",
            "content": "hey I want to book an appointment"
        },
        {
            "role": "assistant",
            "content": "Sure, I can help you with that. Please provide me with your name and the date you would like to book the appointment for."
        },
        {
            "role": "user",
            "content": "myself arun2728"
        }
    ],
    "functions": [
        {
            "name": "book_appointment",
            "description": "Use this function to book an appointment",
            "parameters": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "name of the user"
                    },
                    "date": {
                        "type": "string",
                        "description": "date of appointment"
                    }
                },
                "required": [
                    "name",
                    "date"
                ]
            }
        },
        {
            "name": "fetch_records",
            "description": "Use this function to fetch records",
            "parameters": {
                "type": "object",
                "properties": {
                    "user_id": {
                        "type": "string",
                        "description": "user-id"
                    },
                    "start_date": {
                        "type": "string",
                        "description": "start date of records"
                    },
                    "end_date": {
                        "type": "string",
                        "description": "end date of records"
                    }
                },
                "required": [
                    "user_id",
                    "start_date",
                    "end_date"
                ]
            }
        }
    ],
    "function_call": "auto",
    "temperature": 0,
    "max_tokens": 2048,
    "stream": false,
    "top_p": 1,
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "stop": null
}

Response

{
    "id": "chatcmpl-7ijAqaiW606uZdOw27gdhet1lbyh1",
    "object": "chat.completion",
    "created": 1690894436,
    "model": "gpt-3.5-turbo-0613",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Great, Arun2728! Please let me know the date you would like to book the appointment for."
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 178,
        "completion_tokens": 23,
        "total_tokens": 201
    }
}

Is there any way to handle this at a prompt level?

Hi,

In the system prompt, try telling it that names must be full human names and not usernames, although I’m sure there is someone out there with a name with digits in.

I was working on function calling previously and faced similar issues. It would send me an empty string.
Try making a middleware function to verify parameters based on your requirements, and if they don’t match, make a function response (with role, function name, and content) and add a content that says the name is incorrect or should contain only letters.

Also, you can try improving the parameter’s description and writing something like,
“Name of the user. Can be a combination of English letters only, should not contain special characters or numbers”