Token-level constraints for local models, native JSON modes for cloud APIs - one unified API with explicit guarantee levels, not silent best-effort parsing.
import { z } from "zod";
import { generate, openai } from "@aviasole/shapecraft";
const Person = z.object({
name: z.string(),
age: z.number(),
});
const result = await generate(
openai({ model: "gpt-4o-mini" }),
Person,
"John Doe is 32"
);
result.data
// { name: "John Doe", age: 32 }
result.guaranteeLevel
// "native"npm install @aviasole/shapecraftServer-side strict JSON schema enforcement
JSON mode
JSON mode
Grammar-based cloud constraint
JSON mode
Server-side JSON schema mode
GBNF grammar, token-level
GBNF grammar, token-level, fully local
Prompt + parse + retry
Pass-through, depends on underlying model
Incremental JSON parsing with partial-object events
Koa-style pipeline for logging, retry, timeout defaults
Concurrency-capped generateBatch() across many prompts
Patient, Observation, Condition, MedicationRequest, Encounter
Model dispatches to registered skills, agentic loop support
Native provider function-calling with validated arguments
runAgents() chains validated generate() calls with your own router
Multi-turn collection, validated once over the whole transcript
npx shapecraft validate - check a JSON file against a schema, no code