Hashtag and caption limits in a Sume output schema, checked post-run

Use pattern, maxItems and maxLength in a Sume output_schema so captions and hashtags are checked after the run. A violation returns null output, not bad data.

3 min readSume
All posts

Can a Sume schema enforce a hashtag format and a caption length?

Yes. The structured-output subset enforces pattern, format, minItems, maxItems, minimum, maximum, enum and const, and Sume validates the result after the run with Ajv. A caption with maxLength over the limit, or a sixth hashtag when maxItems is 5, makes the run fail with output_schema_unsatisfied; output is null and output_error says why.

What does the schema look like?

Every object needs additionalProperties: false and every property must be required. The pattern below accepts a hash, then letters, digits or underscores, and nothing else, so spaces and punctuation inside a tag are caught.

{
  "type": "object",
  "additionalProperties": false,
  "required": ["caption", "hashtags"],
  "properties": {
    "caption": {"type": "string", "minLength": 20, "maxLength": 150},
    "hashtags": {
      "type": "array", "minItems": 3, "maxItems": 5,
      "items": {"type": "string", "pattern": "^#[A-Za-z0-9_]{2,30}$"}
    }
  }
}

What happens when the agent gets it wrong?

The check is a gate after the run, not a prompt the agent must obey. Your code gets no output from a failed check, so the right reaction is a retry with a clearer instruction, not an import of whatever text came back. Keep the limits in the instruction as well, so the agent aims for them in the first place.

A practical routine is to start with the limits you need today, run five or ten rows, and read which constraint fails most. If one rule fails often, the agent probably cannot see it, so restate it in the instruction. Mind two limits. Platform rules change, so keep the numbers in one place and check the platform's own page before you hard-code them. And pattern is a regular expression on the string: it can enforce shape, not meaning, so it cannot tell a relevant hashtag from an irrelevant one.

  • Use maxItems for the tag count and pattern for each tag's shape.
  • Set minLength so an empty caption is not valid.
  • Treat output_schema_unsatisfied as retryable with a new idempotency key.
  • Never send output_schema together with response_format; that is a 400.

Sources

Related posts

More in Formats

All Formats posts

Written by Sume