Skip to content

Development & Engineering

Schema Contracts

Free

Validate input at the server boundary and return a stable error shape.

Difficulty intermediate
Version v1.1

Purpose

Keep client-supplied data from becoming queries, paths, or HTML.

Procedure

--- name: schema-contracts description: Validate input at the server boundary and return a stable error shape. ---

Schema Contracts

Purpose

Keep client-supplied data from becoming queries, paths, or HTML.

Procedure

Treat every value from the browser as untrusted, including ids, roles, prices, and "isAdmin" flags.

At the server function or request handler:

  • Accept a known object. Reject extra behavior, not by silently ignoring dangerous fields you then read from a loose type.
  • Check types, lengths, and closed sets (enums). Strings that become queries get a maximum length.
  • Numbers that become limits are bounded.
  • Slugs match a pattern you can say out loud (lowercase, digits, hyphens).

Return errors the UI can show: a short message and, when useful, a field name. Do not return stack traces or SQL.

Do not duplicate a complex schema in two incompatible ways. If the project already has a parser, use it.

Authorization is not validation. A valid skill id still needs an ownership or publication check. Do that next to the query, not only in the form.

Never validate only in the component and assume the server can trust it.

Example requests

1. Validate a report

Request: Apply Schema Contracts to the report submission. Cap lengths and reject unknown reasons. Expected: A server-side check, a clear error, and no trust in hidden fields.

Dependencies

None. Work in the repository that is already open. Do not add packages unless the procedure names one.

Compatibility

This document follows the Agent Skills layout (a folder named schema-contracts containing SKILL.md). Claude Code, Cursor, Codex, and Gemini CLI can load that file from the paths in the Skilling installation guide. GitHub Copilot does not load SKILL.md. Use the Copilot instructions copy, and narrow applyTo before you commit it.

Example prompts

Validate a report

Apply Schema Contracts to the report submission. Cap lengths and reject unknown reasons.

Expected: A server-side check, a clear error, and no trust in hidden fields.

Choose the agent

This skill is installed for one agent at a time. Pick the section you are using.

Related

  • Strict TypeScript

    Tighten types at the boundary you are editing: no any, no fake optionals, names that match the runtime.

  • Query Scoping

    Scope every read and write of personal rows by the session user, in the query itself.

  • Form States

    Build forms with labels, inline errors, pending submits, and no silent failure.

Reviews

No reviews yet.

    Sign in to review.

    Report a problem

    Inaccurate steps, an unsafe instruction, or a licensing concern.

    Sign in to report.