arktype

Write and review ArkType boundary validation schemas for server functions and API routes.

Updated Dec 21, 2025
One-click install
npx skills add https://github.com/Angael/veles --skill arktype-angael
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: arktype
Source: https://github.com/Angael/veles/tree/main/.agents/skills/arktype
Command: npx skills add https://github.com/Angael/veles --skill arktype-angael

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires arktype, date-fns.

What problem does it solve? Hand-written input validation with scattered if checks is verbose, error-prone, and easy to bypass. This Skill guides you to use ArkType as the single boundary validation layer in the Veles repo, so server functions and API routes reject invalid input declaratively with keywords, ranges, unions, and pipes. ## Core Features & Use Cases - Boundary Validation Patterns: Apply arkTypeValidator to TanStack server functions and check type.errors in API routes, with repo-specific rules like logMiddleware and null-coerced optional numeric fields. - Strict Date-Only Validation: Use the shared dateOnlyType from @/lib/dateOnly to enforce exact YYYY-MM-DD shape and calendar validity instead of the permissive string.date. - Quick Reference & Anti-Patterns: A comprehensive catalog of ArkType expressions (strings, numbers, arrays, objects, unions, FormData, files) plus guidance on when custom .narrow() or .filter() is justified. - Use Case: When adding a recipe rating endpoint, define type('string.numeric.parse |> 1 <= number <= 5') directly above the route instead of writing manual range checks after parsing. ## Quick Start Ask the AI to add ArkType validation to a new server function or API route following the repo's boundary validation rules.

Frequently Asked Questions about arktype

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate server function input with ArkType?

Define an ArkType schema directly above the server function and pass it via `.validator(arkTypeValidator(inputType))` on the TanStack `createServerFn` chain. Keep `logMiddleware` in the middleware array per repo rules, and access parsed data through the handler's `data` argument.

How to validate API route input using ArkType type.errors?

Call the ArkType type directly on the input, then check `result instanceof type.errors`. On failure, return a 400 JSON response with `result.summary`; on success, the result is the narrowed, typed value ready for use.

Does ArkType string.date validate strict YYYY-MM-DD dates?

No, `string.date` accepts expanded years like `122324-02-12` and impossible dates like `2026-02-30`. In this repo, use the shared `dateOnlyType` from `@/lib/dateOnly`, which combines `string.date.iso` with date-fns `isMatch` for exact shape and calendar validity.

How do I handle optional numeric form fields in ArkType?

Empty optional numeric form fields should become `null`. Pipe `string.trim` through a custom step that maps empty strings to null and otherwise applies `string.numeric.parse` with range constraints like `1 <= number <= 5`.

When should I use ArkType narrow or filter instead of keywords?

Use `.narrow()` or `.filter()` only when keywords and expression syntax cannot express the constraint cleanly. Prefer built-in keywords, ranges, unions, and pipes first; reserve custom logic for cases like even-number checks or length limits on parsed values.

When are separate if checks acceptable alongside ArkType validation?

Separate `if` checks remain appropriate for auth, permissions, database or storage state, async checks, and business logic. ArkType handles scalar parsing and structural constraints at the boundary; it does not replace runtime state or authorization decisions.