Constrain parameters limits when calling function

Is there any way to specify some ranges for the parameters passed to a function defined in tools?

I have one function that accepts as input arguments start_date and end_date and I want to prevent the model from calling the function with an end_date that is too far in the future. I tried to do that

{
    "type": "function",
    "function": {
        "name": "get_historical_daily_data",
        "description": "Get the daily historical data for a location. ",
        "parameters": {
            "type": "object",
            "properties": {
                "location": location_object,
                "start_date": {
                    "type": "string",
                    "description": "The start date to retrieve historical data. Needs to be in the format YYYY-mm-dd. The minimum value for this parameter is 1940-01-01, the maximum value is 6 days before today.",
                },
                "end_date": {
                    "type": "string",
                    "description": "The end date to retrieve historical data. Needs to be in the format YYYY-mm-dd. The minimum value for this parameter is 1940-01-01, the maximum value is 6 days before today",
                },
            },
            "required": ["location", "start_date", "end_date"],
            "additionalProperties": False,
        },
    },
    "strict": True,
},

but the model seems to ignore the hints about maximum/minimum allowed values. Is there a better way to do it (besides writing the same in the system prompt maybe?).

Welcome to the community!

The models are unfortunately notoriously bad at comparing values. A big meme for a while was “Which is greater, 9.9 or 9.11?”

So this is going to be tough to do in general.

One idea you can try is to change the function signature into something that mimics the input:

i.e.: if the users typically ask, “give me the history up until last week”, that “last week” or “7” “days” is a possible parameter.

Alternatively, you can also simply try to return an error to the model (“out of range. did you mean ‘start date: 1940-01-01’?”)

If necessary, you may need to split it up into a multi step process: first compute the start and end date (potentially with another tool), and then call this particular tool.

Hope this gives you some ideas!

2 Likes

Hey,
thanks for the suggestion.
However, I’m not sure you’re right :slight_smile:

I asked the same model some questions and is indeed capable of doing date arithmetics and has context about today/tomorrow, as I provide a function that can be called to obtain the current date and time.

I think the problem may not be the “base” knowledge of the model, but whether it really uses the information stored into the description of every parameter and function in the tools JSON. That’s what my question was really about :slight_smile: