Issue with an "error 400 string too long"

Hello all,

There is one other thread related to this topic but I thought it couldn’t hurt to start another one for some further clarification. There seems to be an issue when with_structured_output(Classification) is called on the llm. For example:


class Classification(BaseModel):
    energy: str = Field(..., description="What aspect of energy is this related to?")
    energy_related: int = Field(..., description="How related is this to energy on a scale from 1 to 10?")
    tag: str = Field(
        ..., description="Please select a tag from the provided list.",
        enum=[
            "wells", "pipelines", "infrastructure", "imagery", "weather",
            "environmental", "geology", "seismic", "geomatics", "renewables",
            "emissions", "basemaps", "bathymetry"
        ]
    )

Might help to see the tagging_function where invoke() is called:

agent_csv_path = os.path.join(inputFolderPath, 'export-1.csv')

agent = create_csv_agent(llm, agent_csv_path, verbose=True)


def tagging_function(description, tags):
    if description == "No description":
        text = tags
    else:
        text = description

    prompt_input = tagging_prompt.format(input=text)
    result = agent.invoke(prompt_input)

    return {
        'energy': result.energy,
        'energy_related': result.energy_related,
        'tag': result.tag
    }

Any suggestions on how to get around this error 400 issue:
Error code: 400 - {‘error’: {‘message’: “Invalid ‘tools[0].function.description’: string too long. Expected a string with maximum length 1024, but got a string with length 1824 instead.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘tools[0].function.description’, ‘code’: ‘string_above_max_length’}}

1 Like

I have the same use case as yours and am facing the same error as you. It used to work without issues until like a month ago.

1 Like

Also running into this error while building an AI chatbot with N8N. Any ideas? Thanks!

API limitation: structured function description fields cannot exceed 1024 characters in length.

Any Ideas: If your function needs to describe how to be used in more than 1024 characters, move instruction of how to produce properties to the property descriptions themselves, and use enum for properties where you want a selection from only a list of self-describing strings (up to 500), or an anyOf to have two schemas of different purpose or ability to emit a different set of strings.

1 Like

use these versions

langchain==0.3.13 langchain-core==0.3.28 langchain-openai==0.2.14