Skip to content
Structured output for LLMs

Reliable structured AI runtime for Node.js

Token-level constraints for local models, native JSON modes for cloud APIs - one unified API with explicit guarantee levels, not silent best-effort parsing.

native shapecraft
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/shapecraft
Backends

Guarantee levels

native

openai()

Server-side strict JSON schema enforcement

native

groq()

JSON mode

native

deepseek()

JSON mode

native

fireworks()

Grammar-based cloud constraint

native

mistral()

JSON mode

native

gemini()

Server-side JSON schema mode

constrained

ollama()

GBNF grammar, token-level

constrained

node-llama-cpp()

GBNF grammar, token-level, fully local

best-effort

anthropic()

Prompt + parse + retry

best-effort

openRouter()

Pass-through, depends on underlying model

Also included

What else is in the box

Streaming

Incremental JSON parsing with partial-object events

createClient() middleware

Koa-style pipeline for logging, retry, timeout defaults

Batch generation

Concurrency-capped generateBatch() across many prompts

FHIR R4 presets

Patient, Observation, Condition, MedicationRequest, Encounter

Skill-based generation

Model dispatches to registered skills, agentic loop support

Tool calling

Native provider function-calling with validated arguments

Multi-agent orchestration

runAgents() chains validated generate() calls with your own router

Turnaround

Multi-turn collection, validated once over the whole transcript

CLI

npx shapecraft validate - check a JSON file against a schema, no code

FAQ

Common questions

+ What does a guarantee level actually guarantee?
+ Do I need to install every backend's SDK?
+ Can I bring my own JSON Schema validator?

Released under the Apache-2.0 License.