Tool calling API upgrade - 1024 char limit is limiting

Hi,

I am unable to use gpt-4o or any other models for my use because of 1024 character limit on tool call descriptions. We auto generate the descriptions and are advertently verbose because its valuable for the work we are doing.

Are you sure that is the case? Iā€™m able to send much larger descriptions without any issues.


import tooldantic as td
import typing
import openai

client = openai.OpenAI()


class Test(td.OpenAiBaseModel):
    test: str = td.Field(description="A test field." * 3000)
    
r = client.chat.completions.create(
    model="gpt-4o-mini",
    tools=[Test.model_json_schema()],
    messages=[
        {"role": "user", "content": "thanks"},
    ],
)

What is the version of your open ai client?

 File "/Users/prannayk/Library/Caches/pypoetry/virtualenvs/sentinel-gjiWBBWm-py3.10/lib/python3.10/site-packages/openai/_base_client.py", line 1049, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'tools[1].function.description': string too long. Expected a string with maximum length 1024, but got a string with length 1090 instead.", 'type': 'invalid_request_error', 'param': 'tools[1].function.description', 'code': 'string_above_max_length'}}

Aha, your model json schema is setting the description of the parameter of the tool, not the description of the tool itself. I tried your test case and your description of the tool name itself is empty.

In [27]: Test.model_json_schema()['function']['description']
Out[27]: ''
1 Like

Are you sure thatā€™s the case? Not using home-made libraries and sending so it actually is structured-activating:

import os, httpx, json

api_key = os.getenv("OPENAI_API_KEY")
headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-4o-2024-08-06", "max_tokens": 200,
    "messages": [
        {"role": "user", "content": "Who's a good bot? YOU!"},
    ],
    "tools": [
{
"type": "function",
"function": {
    "name": "get_current_weather",
    "description": "Get the current weather on a planet. " * 100,
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The planet, e.g. Jupiter"
            },
            "unit": {
                "type": "string",
                "enum": ["celsius", "kelvin"],
                "description": "Temperature unit"
            }
        },
        "required": ["location", "unit"],
        "additionalProperties": False
    },
    "strict": True
    }
}
    ],
    "tool_choice": "auto"
}

try:
    response = httpx.post("https://api.openai.com/v1/chat/completions",
                          headers=headers,
                          data=json.dumps(data))
    response.raise_for_status()
except httpx.HTTPStatusError as exc:
    print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")
    print(f"Response body:\n{exc.response.text}")
else:
    print(response.json())

Error response 400 while requesting URL('https://api.openai.com/v1/chat/completions').
Response body:
{
ā€œerrorā€: {
ā€œmessageā€: ā€œInvalid ā€˜tools[0].function.descriptionā€™: string too long. Expected a string with maximum length 1024, but got a string with length 3700 instead.ā€,
ā€œtypeā€: ā€œinvalid_request_errorā€,
ā€œparamā€: ā€œtools[0].function.descriptionā€,
ā€œcodeā€: ā€œstring_above_max_lengthā€
}
}

2 Likes

Yes. Tool descriptions should be succinct and provide a brief directive for the ai. Example, ā€œUse this tool to do x when yā€, which is important for tool selection. As for the parameters, this is where you want to get deep into the embedding of system instructions into the tool.

1 Like

Thanks for the clarification, @_j . I see where I made the mistakeā€”youā€™re absolutely right about the 1024-character limit being on the function description itself, while I was thinking about the parameter descriptions, which donā€™t have that same restriction. So, I appreciate you pointing that out.

But this brings up a bigger questionā€”is the 1024-character limit on the function description really a limitation? From everything Iā€™ve seen, especially in OpenAIā€™s examples, the model seems tuned to use the function description as a short directive for tool selection, while the parameters are where the real detailed guidance happens. If you truly need more tool description verbosity, you could always supplement the function description with a more detailed system message. But Iā€™d argue that the most important thing is having well-described parametersā€”those are what the model uses to drive its generation through the constrained outputs.

So, Iā€™d challenge the assumption that the 1024-character limit is a hard barrier. If you can show me a case where a function description over 1024 characters is necessary, Iā€™d be happy to counter with an example where a combination of a system message and thorough parameter descriptions could yield even better results.

Iā€™d push back on the ā€œhome-madeā€ label. Tooldantic is not some cobbled-together solution. Itā€™s a thin, targeted extension of pydantic, which is the gold standard for validation in Python. All it does is make pydantic more suited to handling LLM outputs in a clean and structured way. Every part of it runs through pydantic, so itā€™s built on a foundation thatā€™s already widely trusted and used in the Python community. Far from being ā€œhome-made,ā€ itā€™s just adding a specific layer of utility to a tool thatā€™s already deeply ingrained in the ecosystem.

At the end of the day, pydantic is the core hereā€”so if you trust pydantic (and most Python devs do), tooldantic is just an extension that makes it easier to work with LLMs.

1 Like

Yes, it is an odd case to expect that beyond 1000 characters is required for ā€œReturns OpenAI developer support solutionsā€, when you are guiding the production of language in the properties. The description should be a ā€œcall or noā€ decision point. If you want to double or triple that 250 English tokens placed into AI context, write it in Chinese, though.

However, client libraries shouldnā€™t truncate input without error, and must also operate correctly and transparently to activate the desired modality.

1 Like