Gift message field in a strict output schema: optional means nullable

In a Sume output_schema every property must be required, so an optional gift message is a string-or-null union, not an omitted key. Here is the shape.

3 min readSume
All posts

You cannot leave a property out of required in a Sume strict schema. A gift message that exists for some SKUs and not others is declared as { "type": ["string", "null"] }, and the agent returns null when there is none.

The rules that cause the 400

  • The root must be an object.
  • Every object needs additionalProperties: false.
  • Every property must appear in required.
  • Only an allowlist of keywords is accepted: anyOf, enum, const, pattern, minLength and similar. oneOf, allOf and nullable are rejected.
  • The schema name is 1 to 64 characters from A-Za-z0-9._/-.

The wrong and the right shape

A schema that lists gift_message in properties but not in required fails validation at submit time. The fix is one line.

{
  "type": "object",
  "additionalProperties": false,
  "required": ["headline", "gift_message"],
  "properties": {
    "headline": { "type": "string" },
    "gift_message": { "type": ["string", "null"] }
  }
}

Why null instead of an empty string

null tells your code the agent had nothing to say; an empty string looks like a real value. Branch on it in your catalog import and you avoid printing a blank gift card. Limits to keep in mind: depth 10, 5,000 properties, 1,000 enum values and 120,000 string characters across the schema.

Sources

Related posts

More in Formats

All Formats posts

Written by Sume