Skip to main content

Schema Validation

Provide a JSON Schema and Shim will validate and coerce types during repair.

Why Use Schemas

Without a schema, Shim only fixes syntax (brackets, commas, markdown fences). With a schema, Shim also:
  • Coerces types ("30"30)
  • Detects missing required fields
  • Removes extra fields (strict mode)
  • Validates nested objects

Basic Schema


Type Coercion

Shim coerces types when safe: Unsafe coercions are rejected:
  • "abc"number (not a valid number)
  • "maybe"boolean (not "true" or "false")

Required Fields

Mark fields as required:

Strict vs Lenient Mode

Strict Mode (default)

Removes extra fields not in schema:

Lenient Mode

Keeps extra fields:

Nested Objects

Validate nested structures:

Arrays

Validate array items:

Enums

Restrict values to specific options:

Default Values

Shim does NOT add default values. If a field is missing and not required, it stays missing. Use your application logic to add defaults after repair.

Schema Repairs in Metadata

All schema repairs are logged:

Best Practices

  1. Start with lenient mode during development
  2. Switch to strict mode in production (prevents data leakage)
  3. Mark critical fields as required
  4. Use enums for status fields
  5. Review metadata.schema_repairs if confidence is "medium" or "low"

Next Steps

Batch Endpoint

API reference for batch repair

Response Object

Full response schema

Error Handling

Handle validation failures

TypeScript SDK

Use the official SDK