AISchemaWorkflow AutomationOperations

AI Ignores Your Character Limit? Enforce It in Code

An AI model ignores a character limit because it writes in tokens and cannot count characters as it goes, and as of November 2026 none of the three major APIs enforces maxLength while generating: Claude rejects it with a 400 unless an SDK helper moves it into the description, OpenAI strict mode does not support it, and Gemini silently strips it. The limit has to be measured and enforced in your own code, with a retry that states the measured length and a template fallback instead of truncation.

Alexey YushkinFounder, GENERAL INFORMATICS2 min read

Frequently Asked Questions

The model generates tokens, which are chunks of text of varying length, and it has no running character count while it writes. An instruction like 'under 160 characters' is a target it estimates, not a rule it can check. The output lands near the limit often enough to pass a demo and over it often enough to break a live workflow.

Not during generation on any of the three major APIs, as of November 2026. Anthropic's structured outputs return a 400 for maxLength in a raw schema, and its Python and TypeScript helpers strip it, add it to the field description, and validate the response afterward. OpenAI's strict mode lists only pattern and format for strings, and Gemini's API strips minLength and maxLength without an error.

Not as a length limit. max_tokens stops generation when the cap is hit, so the text ends mid-sentence instead of being written shorter. The response reports it as stop_reason max_tokens on Claude or finish_reason length on OpenAI. Keep max_tokens as a safety ceiling and enforce the character limit with a check in code.

Not for anything a customer or a system reads. Truncation cuts whatever comes last, which in a text message is usually the link, the time, or the opt-out line. Retry with the measured length first, and if the retries fail, send a fixed template that is known to fit.

The message probably contained a character outside the GSM-7 set, such as a curly apostrophe, an em dash, or an accented name. One such character switches the whole message to UCS-2, where a single segment holds 70 characters instead of 160. Normalize punctuation before you measure, and measure in segments, not characters.

SOURCES & CITATIONS

  1. Structured outputs — Anthropichttps://platform.claude.com/docs/en/build-with-claude/structured-outputs
  2. Structured model outputs — OpenAIhttps://developers.openai.com/api/docs/guides/structured-outputs
  3. Structured output — Googlehttps://aistudio.google.com/docs/structured-output

About Alexey Yushkin

Alexey is the founder of GENERAL INFORMATICS LLC. He designs and ships AI and automation systems for businesses and operators across the US.

Connect on LinkedIn

Related reading

Want this kind of system in your business?

We build practical AI and automation systems for operators. Send us your current workflow and we will show you what to automate first.