| name | ari-zod-schemas |
| description | Zod schema management for ARI's type-safe runtime validation |
| triggers | ["create schema","validate types","zod schema","add config validation"] |
ARI Zod Schema Management
Purpose
ARI uses Zod for all config and data structure validation (ADR-006). This skill ensures:
- All new types have corresponding Zod schemas
- Runtime validation matches TypeScript types
- Config changes update schemas first
- Environment variables are validated
ARI's Schema Location
All Zod schemas live in: src/kernel/types.ts
Core Schemas
const TrustLevelSchema = z.enum([
'SYSTEM',
'OPERATOR',
'VERIFIED',
'STANDARD',
'UNTRUSTED',
'HOSTILE'
]);
const AuditEventSchema = z.object({
id: z.string().uuid(),
timestamp: z.string().datetime(),
action: z.string(),
agent: z.string().optional(),
details: z.record(z.unknown()),
previousHash: z.string(),
hash: z.string()
});
const MessageSchema = z.object({
id: z.string().uuid(),
content: z.string(),
trustLevel: TrustLevelSchema,
timestamp: z.string().datetime(),
metadata: z.record(z.unknown()).optional()
});
Workflow
When Adding New Types
- Define Zod schema FIRST in types.ts
- Export inferred TypeScript type
- Use schema for validation at boundaries
- Add tests for schema validation
export const NewFeatureSchema = z.object({
name: z.string().min(1),
enabled: z.boolean().default(true),
config: z.record(z.string())
});
export type NewFeature = z.infer<typeof NewFeatureSchema>;
const validated = NewFeatureSchema.parse(untrustedInput);
When Adding Environment Variables
- Update env schema in config.ts
- Update .env.example
- Update .env
- Update code
const EnvSchema = z.object({
ARI_PORT: z.coerce.number().default(3141),
ARI_LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
});
Schema Patterns for ARI
Event Payloads
const EventPayloadSchema = z.discriminatedUnion('type', [
z.object({ type: z.literal('message'), data: MessageSchema }),
z.object({ type: z.literal('audit'), data: AuditEventSchema }),
]);
Config Validation
const ConfigSchema = z.object({
gateway: z.object({
host: z.literal('127.0.0.1'),
port: z.number().min(1024).max(65535)
}),
security: z.object({
maxRiskScore: z.number().min(0).max(1).default(0.8)
})
});
Security Considerations
- Always validate external input with Zod
- Use
.strict() to reject unknown keys
- Sanitize before validation (injection patterns)
- Log validation failures to audit trail