Practical thinking about AI tools and everyday work.

JSON Schema additionalProperties controls what happens to unexpected keys

A programmer comparing notes on two unreadable code screens.
AI-generated photographic illustration; not documentary photography.

An extraction workflow may return the expected field and add an extra one that the next system cannot accept. JSON Schema can describe whether those unexpected properties are allowed. The relevant keyword is additionalProperties.

The official JSON Schema object reference explains how it works alongside properties and patternProperties. Setting it to false rejects properties not covered by those declarations at that object level.

Test three small objects

{
  "type": "object",
  "properties": {
    "city": { "type": "string" }
  },
  "required": ["city"],
  "additionalProperties": false
}

Against this illustrative schema, {"city":"Leeds"} passes. Adding "note":"probably" creates an unexpected property and fails. An empty object also fails, but for a different reason: the required city property is missing.

Those cases separate two controls that are easy to confuse. Declaring a property does not automatically require its presence. Rejecting extra properties does not establish that every expected property has been supplied.

Decide what failure means in the workflow

Suppose an AI extraction step produces the extra note because the source document is ambiguous. A validation failure can send the record for review or trigger a carefully defined retry. It should not silently turn a guess into a verified city merely by removing the note.

Validation itself is not a universal instruction to strip fields. Check the validator’s actual behaviour and configuration. Keep the original result where appropriate for investigation, then record why a corrected version was accepted.

Nested objects need their own rules. Closing the outer object does not automatically forbid every unexpected key inside a nested address or customer object. Test a deliberately added inner key as well as an outer one.

Finally, a valid string can still contain an incorrect city. This schema controls structure and basic type, not truth. The source comparison and any semantic checks remain separate steps. A strict shape is useful precisely when its limits are understood.