config-validation-and-normalization

A set of rules for checking configuration files with Arktype, a TypeScript validation library, and filling in missing values with defaults.

In plain words
What is it for?
Use it when building a configuration function such as defineConfig(). It covers validating required, optional, and nested fields, then returning normalized settings.
Why use it?
It catches wrongly shaped configuration early and gives readable errors. It also ensures later code receives complete, predictable settings instead of raw input.

Cursor rule for Codex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/prisma/prisma-next/config-validation-and-normalization
Clone the repo
git clone --depth 1 https://github.com/prisma/prisma-next

Made for: Codex.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 932 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00932
Opus 5 $0.00000 $0.00466
Sonnet 5 $0.00000 $0.00186
Haiku 4.5 $0.00000 $0.00093

Measured 2d ago against content hash 807e0069048e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

config-validation-and-normalization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/rules/config-validation-and-normalization.mdc · 122 lines

How it starts

The opening of the file, as written. The whole thing — 122 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Config Validation and Normalization

When implementing config files (e.g. prisma-next.config.ts), use Arktype for validation and normalization. This gives type safety, clear error messages, and sensible defaults.

Pattern: Validate + Normalize in defineConfig()

import { type } from 'arktype';
import { join, dirname } from 'node:path';

const ConfigSchema = type({
  required: 'string',
  'optional?': 'string',
  nested: type({ 'nestedOptional?': 'number' }),
});

export function defineConfig(config: ConfigInput): ConfigOutput {
  // 1. Validate structure with Arktype
  const validated = ConfigSchema(config);
  if (validated instanceof type.errors) {
    const messages = validated.map((p: { message: string }) => p.message).join('; ');
    throw new Error(`Config validation failed: ${messages}`);
  }
  // 2. Normalize by applying defaults
  const normalized: ConfigOutput = {
    ...config,
    optional: config.optional ?? 'default-value',
    nested: { ...config.nested, nestedOptional: config.nested?.nestedOptional ?? 42 },
  };
  // 3. Return the normalized IR (not the raw input)
  return normalized;
}

Validation catches structural errors early with clear messages; normalization applies defaults in one place; Arktype keeps structure aligned with TypeScript types.

Normalization Responsibilities

defineConfig() is the ONLY place normalization happens. It validates structure, applies defaults for optional fields, returns the normalized config IR, and throws on invalid structure. It should always output a fully normalized config. All other components assume configs are already normalized:

  • Config loader — loading only. Loads the config file (c12 or similar) and calls defineConfig() to validate/normalize, then returns the result. Does NOT set defaults or normalize structure.
  • Command handlers — using only. Use normalized values directly, accessing fields without checking for defaults. Do NOT set defaults or normalize structure.
  • Validators. Never normalize.

Read the full file on GitHub · 122 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 122 lines · 0 tokens per session scan A 807e0069048e

Subscribe to this mod's changes

config-validation-and-normalization is a cursor rule published in the GitHub repository prisma/prisma-next (420 stars, last pushed 7d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 932 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.