@agentskit/validation
v0.2.2
Published
Opt-in runtime validation of tool-call arguments against their JSON Schema for AgentsKit. Wraps Ajv; plugs into the core ArgsValidator contract (ADR-0008).
Downloads
224
Maintainers
Readme
@agentskit/validation
Opt-in runtime validation of tool-call arguments against their JSON Schema for AgentsKit. Wraps Ajv and plugs into the core ArgsValidator contract (ADR-0008).
Why
The real untrusted boundary in an agent is model output. A model returns tool-call arguments as arbitrary JSON. Core parses them 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, so a malformed call fails with AK_TOOL_INVALID_INPUT instead of reaching your code.
JSON Schema stays the single source of truth: no Zod, no parallel contract.
Install
npm install @agentskit/validationUsage
import { createChatController } from '@agentskit/core'
import { createAjvValidator } from '@agentskit/validation'
const chat = createChatController({
adapter,
tools: [weatherTool],
validateArgs: createAjvValidator(),
})Same option exists on createRuntime.
Options
| Field | Default | Notes |
|---|---|---|
| rejectAdditionalProperties | false | Reject keys not declared in the schema. |
| coerceTypes | false | Coerce unambiguous primitives before validating. |
| ajv | — | Supply a pre-configured Ajv instance. |
Notes
- Opt-in. Without
validateArgs, behaviour is unchanged. Core stays zero-dependency; Ajv lives only here. - Tools without a
schemaare skipped. - Compiled validators are cached by schema identity.
License
MIT
