Implements schema validation across JSON Schema, Pydantic, and Joi to enforce request, config, and message contracts.
Agentic Workflow: Read -> Reason -> Act (data-validation)
You are Data Validation (backend/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for data-validation
- Domain: Implements schema validation across JSON Schema, Pydantic, and Joi to enforce request, config, and message contracts.
- json-schema-validation: Validate JSON documents against schemas from the CLI. —
ajv validate -s schema.json -d data.json
- runtime-validation: Generate and use runtime validators in Python and Node. —
python -m pip install pydantic
- Check
knowledge and prerequisites: ajv, npm, npx, python
2. Reason — think for data-validation
- For
json-schema-validation: Validate JSON documents against schemas from the CLI. — decide which checks to run
- For
runtime-validation: Generate and use runtime validators in Python and Node. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with data-validation tools
- Tools:
Glob, Grep, Read, Ajv, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
data-validation:6cac48dd
Data Validation
Enforce data contracts at API boundaries, config load, and message ingestion.
When to Use
- Validating HTTP request bodies and query params
- Parsing environment variables and config files
- Validating messages consumed from queues
- Catching malformed data before it reaches business logic
Commands
# Validate one file with Ajv
ajv validate -s schema.json -d data.json
# Show all errors
ajv validate -s schema.json -d data.json --all-errors
# Compile a schema to check it is valid
ajv compile -s schema.json
# Python jsonschema CLI
python -m jsonschema -i instance.json schema.json
# Generate a schema from TypeScript types
npx ts-json-schema-generator --path src/types.ts --type User
Schema Example
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["email", "age"],
"properties": {
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0 }
},
"additionalProperties": false
}
Pydantic Example
from pydantic import BaseModel, EmailStr, Field
class User(BaseModel):
email: EmailStr
age: int = Field(ge=0, le=120)
Best Practices
- Validate at the boundary only; keep internal code assumption-free
- Use additionalProperties: false to catch typos in payloads
- Reject unknown enum values instead of defaulting silently
- Add format validators for email, uri, and date-time
- Test schemas with representative invalid samples in CI
Capabilities
json-schema-validation
Validate JSON documents against schemas from the CLI.
Parameters:
schema (string): Path to JSON schema file
data (string): Path to JSON instance file or glob
all-errors (boolean): Report all errors instead of the first
Commands:
ajv validate -s schema.json -d data.json
ajv compile -s schema.json
python -m jsonschema -i instance.json schema.json
npx ts-json-schema-generator --path src/types.ts --type User
ajv validate -s schema.json -d "data/*.json"
Examples:
- ajv validate -s schema.json -d data.json --all-errors
- python -m jsonschema -i data.json schema.json
- ajv compile -s schema.json --strict=false
runtime-validation
Generate and use runtime validators in Python and Node.
Parameters:
language (string): Target stack: python or node
framework (string): Validation library: pydantic, joi, ajv
Commands:
python -m pip install pydantic
python -c "from pydantic import BaseModel; print(BaseModel.__module__)"
npm install joi
npx ajv-cli validate -s schema.json -d data.json
Examples:
- python -c "from pydantic import TypeAdapter; print(TypeAdapter(int).validate_python(1))"
- npx ajv-cli compile -s schema.json
References
1---2name: "data-validation"3description: "Implements schema validation across JSON Schema, Pydantic, and Joi to enforce request, config, and message contracts. Use when working with json schema validation, runtime validation, backend or when the user mentions json schema validation, runtime validation, backend."4license: "MIT"5compatibility: "Requires ajv, npm, npx, python."6metadata:7 source: https://skillmd.com/skills/opknock/data-validation8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(ajv:*) Bash(npm:*) Bash(npx:*) Bash(python:*)"12---1314Implements schema validation across JSON Schema, Pydantic, and Joi to enforce request, config, and message contracts.1516## Agentic Workflow: Read -> Reason -> Act (data-validation)1718You are **Data Validation** (backend/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `data-validation`21- Domain: Implements schema validation across JSON Schema, Pydantic, and Joi to enforce request, config, and message contracts.22- **json-schema-validation**: Validate JSON documents against schemas from the CLI. — `ajv validate -s schema.json -d data.json`23- **runtime-validation**: Generate and use runtime validators in Python and Node. — `python -m pip install pydantic`24- Check `knowledge` and `prerequisites: ajv, npm, npx, python`2526### 2. Reason — think for `data-validation`27- For `json-schema-validation`: Validate JSON documents against schemas from the CLI. — decide which checks to run28- For `runtime-validation`: Generate and use runtime validators in Python and Node. — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `data-validation` tools32- Tools: `Glob`, `Grep`, `Read`, `Ajv`, `Bash` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `data-validation:6cac48dd`3536# Data Validation3738Enforce data contracts at API boundaries, config load, and message ingestion.3940## When to Use4142- Validating HTTP request bodies and query params43- Parsing environment variables and config files44- Validating messages consumed from queues45- Catching malformed data before it reaches business logic4647## Commands4849```bash50# Validate one file with Ajv51ajv validate -s schema.json -d data.json5253# Show all errors54ajv validate -s schema.json -d data.json --all-errors5556# Compile a schema to check it is valid57ajv compile -s schema.json5859# Python jsonschema CLI60python -m jsonschema -i instance.json schema.json6162# Generate a schema from TypeScript types63npx ts-json-schema-generator --path src/types.ts --type User64```6566## Schema Example6768```json69{70 "$schema": "https://json-schema.org/draft/2020-12/schema",71 "type": "object",72 "required": ["email", "age"],73 "properties": {74 "email": { "type": "string", "format": "email" },75 "age": { "type": "integer", "minimum": 0 }76 },77 "additionalProperties": false78}79```8081## Pydantic Example8283```python84from pydantic import BaseModel, EmailStr, Field8586class User(BaseModel):87 email: EmailStr88 age: int = Field(ge=0, le=120)89```9091## Best Practices9293- Validate at the boundary only; keep internal code assumption-free94- Use additionalProperties: false to catch typos in payloads95- Reject unknown enum values instead of defaulting silently96- Add format validators for email, uri, and date-time97- Test schemas with representative invalid samples in CI9899## Capabilities100101### json-schema-validation102Validate JSON documents against schemas from the CLI.103104**Parameters:**105- `schema` (string): Path to JSON schema file106- `data` (string): Path to JSON instance file or glob107- `all-errors` (boolean): Report all errors instead of the first108109**Commands:**110- `ajv validate -s schema.json -d data.json`111- `ajv compile -s schema.json`112- `python -m jsonschema -i instance.json schema.json`113- `npx ts-json-schema-generator --path src/types.ts --type User`114- `ajv validate -s schema.json -d "data/*.json"`115116**Examples:**117- ajv validate -s schema.json -d data.json --all-errors118- python -m jsonschema -i data.json schema.json119- ajv compile -s schema.json --strict=false120121### runtime-validation122Generate and use runtime validators in Python and Node.123124**Parameters:**125- `language` (string): Target stack: python or node126- `framework` (string): Validation library: pydantic, joi, ajv127128**Commands:**129- `python -m pip install pydantic`130- `python -c "from pydantic import BaseModel; print(BaseModel.__module__)"`131- `npm install joi`132- `npx ajv-cli validate -s schema.json -d data.json`133134**Examples:**135- python -c "from pydantic import TypeAdapter; print(TypeAdapter(int).validate_python(1))"136- npx ajv-cli compile -s schema.json137138## References139- [JSON Schema](https://json-schema.org/)140- [Pydantic Docs](https://docs.pydantic.dev)141- [Ajv Docs](https://ajv.js.org)