@agentskit/validation — for agents
Opt-in runtime validation of tool-call arguments against their JSON Schema. Wraps Ajv; plugs into the core ArgsValidator contract (ADR-0008).
#Install
npm install @agentskit/validation#Why
The real untrusted boundary in an agent is model output. A model returns tool-call args as arbitrary JSON; core parses them (safeParseArgs) but does not check them against the tool's schema — execute receives args the type system only claims are valid. This package enforces the tool's existing JSONSchema7 at runtime. JSON Schema stays the single source of truth (ADR-0008); no Zod, no duplicate contract.
#Primary exports
createAjvValidator(options?)— returns anArgsValidator(the core contract) backed by Ajv. Pass it asvalidateArgson the chat controller or runtime config. Invalid args raiseAK_TOOL_INVALID_INPUTbeforeexecuteruns.
#Options (AjvValidatorOptions)
| Field | Default | Notes |
|---|---|---|
rejectAdditionalProperties | false | Reject keys not declared in the schema. Models often add harmless extras; enable for strict contracts. |
coerceTypes | false | Coerce unambiguous primitives (e.g. "42" → 42) before validating. |
ajv | — | Supply a pre-configured Ajv instance (formats, keywords, strict mode). |
#Usage
import { createChatController } from '@agentskit/core'
import { createAjvValidator } from '@agentskit/validation'
const chat = createChatController({
adapter,
tools: [weatherTool],
validateArgs: createAjvValidator(),
})Same shape on the runtime:
import { createRuntime } from '@agentskit/runtime'
import { createAjvValidator } from '@agentskit/validation'
const runtime = createRuntime({ adapter, tools, validateArgs: createAjvValidator() })#Notes
- Opt-in. Omit
validateArgsand behaviour is unchanged (passthrough). Core stays zero-dependency; Ajv lives only here. - Single source of truth. Validates the
schemaalready on eachToolDefinition. Tools with noschemaare skipped. - Compiled validators are cached by schema identity — repeated calls do not recompile.
- See ADR-0008 (
docs/architecture/adrs/0008-runtime-validation.md).
Explore nearby
- PeerFor agents — overview
Dense, LLM-friendly reference for every AgentsKit package. Designed to paste into an agent's context window.
- Peer@agentskit/core — for agents
Zero-dependency foundation. Contracts, chat controller, primitives, and a dozen feature subpaths.
- Peer@agentskit/adapters — for agents
Provider adapters (OpenAI-compatible + native) + router + ensemble + fallback + generic factory.