Skip to content
jammaruPublic

Latest commit

 

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

llm-abi

llm-abi

A schema compatibility compiler for LLM providers.

One schema in. Provider-safe schemas out — with diagnostics, loss reporting, runtime validation, and CI checks.

CI npm license

Docs · Playground · 日本語

If llm-abi looks useful, a GitHub ⭐ is appreciated.


Quick start

npm i llm-abi
import { compile } from "llm-abi";

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
  },
  required: ["name"],
};

const result = compile(schema, "anthropic");

result.schema;
result.compatibility;
result.validate({ name: "Ada" });
npx llm-abi check schema.json
Schema compatibility

Target                                 Result   Tokens
────────────────────────────────────────────────────────
openai/responses/structured            PASS*    142
anthropic/messages/structured          PASS*    168
google/gemini/structured               PASS     155

2 constraints require runtime validation.

Use llm-abi when

  • One generated or hand-written schema must work across multiple LLM providers.
  • You need to catch provider rejection and silent constraint loss before an API call.
  • You want a build/CI gate without adopting another agent framework or provider SDK.
  • You need the emitted provider schema and a runtime validator for constraints the provider cannot enforce.

Use a provider SDK, AI SDK, Instructor, or BAML for making model calls, retries, and application orchestration. llm-abi sits underneath those tools: compile the schema, then pass result.schema to the SDK you already use.

Why

LLM providers all say they accept JSON Schema. They do not accept the same JSON Schema.

Provider What actually happens
OpenAI Strict structured outputs use a JSON Schema subset
Anthropic Unsupported constraints are stripped and moved to descriptions
Gemini Officially a subset; large or deep schemas can be rejected
MCP hosts The protocol accepts JSON Schema, but deployed host support can be narrower

llm-abi is not another Zod-to-JSON-Schema converter. It is a schema compatibility compiler: one input schema, provider-aware lowering, diagnostics, loss reporting, conservative size/token hints, runtime validation, and a CI checker.

Try that loop in the compatibility playground. Compilation runs in the browser. Profiles ship with the package. Each target exposes its evidence source and verification date. There is no compatibility percentage.

Same oneOf schema: lossy on OpenAI, unsupported on Gemini

The same oneOf schema can be lossy on one target and unsupported on another.

Where it fits

Tool category Primary job llm-abi relationship
Zod / Valibot / ArkType Define and validate application data Accept their Standard JSON Schema output
OpenAI / Anthropic / Gemini SDKs Call one provider Compile before assigning the SDK schema field
Vercel AI SDK / Instructor / BAML Generation, parsing, retries, orchestration Complementary; llm-abi is the provider-compatibility gate
Provider-specific schema converters Make a schema fit one provider or client surface Use llm-abi when one source must target several providers

Install

npm install llm-abi
import { compile, check, checkRequest, analyze, fingerprint } from "llm-abi";

Zero runtime dependencies. The compiler library is about 14 KB gzip. Node, Bun, Deno, browsers, and edge runtimes can import it. The CLI requires Node.js 22+.

Usage

import { compile } from "llm-abi";

const UserSchema = {
  type: "object",
  properties: {
    name: { type: "string", minLength: 1 },
    age: { type: "number", minimum: 0, maximum: 150 },
    nickname: { type: "string" },
  },
  required: ["name", "age"],
};

const result = compile(UserSchema, "anthropic");

compile(schema, "openai") is enough. Options exist for people who need them:

compile(UserSchema, {
  target: "anthropic/messages/structured",
  strict: true,
  constraintFallback: "description",
});

Copy-paste recipes under examples/ place result.schema in the OpenAI, Anthropic, Gemini, Vercel AI SDK, and MCP fields those SDKs already document. They do not call those APIs, and they do not add those SDKs to packages/core.

Compatibility

Every compile result has a discrete compatibility level. There is no invented percentage score.

Level Meaning
lossless Provider schema preserves the input semantics
runtime-safe Provider cannot enforce some constraints; result.validate still can
lossy Semantics changed (for example oneOf → anyOf)
unsupported The construct cannot be represented; diagnostics explain why
result.loss;
// {
//   level: "runtime-safe",
//   removed: [{ path: ["age"], keyword: "minimum", fallback: "runtime-validation" }]
// }

Input

  • JSON Schema objects (draft-07 / 2020-12)
  • Standard JSON Schema (~standard.jsonSchema)
  • A closed TypeScript type subset (type / interface syntax). No tsc, no imports.
compile(
  `
    type User = {
      name: string;
      age: number;
      nickname?: string;
    }
  `,
  "openai",
);

Zod, Valibot, ArkType, and other Standard Schema libraries work when they expose JSON Schema conversion. Validation-only Standard Schema objects are rejected with a clear error. llm-abi does not depend on Zod.

Targets

Maturity and evidence are separate. Supported means the profile is maintained with fixtures; it does not claim a live API check. “Last verified” is the date the profile was checked against the linked evidence source.

Alias Profile Maturity Evidence Last verified Live adapter
openai openai/responses/structured Supported documented 2026-08-18 Nightly
anthropic anthropic/messages/structured Supported documented 2026-08-18 Nightly
gemini google/gemini/structured Supported documented 2026-08-18 Nightly
deepseek deepseek/chat/strict-tools Supported documented 2026-08-18 —
xai xai/grok/structured Supported documented 2026-08-18 —
qwen alibaba/qwen/tools Supported documented 2026-08-18 —
mistral mistral/chat/structured Experimental sdk-observed 2026-08-18 —
openrouter openrouter/structured Partial documented 2026-08-18 —
mcp mcp/2026-06/tools Partial documented 2026-08-18 —

The MCP target is deliberately conservative for deployed hosts. The current protocol specification allows a full JSON Schema object; a future protocol target and host-specific compatibility profiles are tracked separately.

qwen is Alibaba Model Studio, not a laptop Qwen GGUF. Local / self-hosted schema engines are separate Experimental targets. They are compile-addressable and stay out of default check():

Alias Profile Maturity Evidence Last verified Live adapter
llamacpp llamacpp/server/structured Experimental documented 2026-08-28 —
lmstudio/gguf lmstudio/gguf/structured Experimental documented 2026-08-28 —
lmstudio/mlx lmstudio/mlx/structured Experimental documented 2026-08-28 —
ollama ollama/chat/structured Experimental documented 2026-08-28 —
vllm vllm/openai/structured Experimental documented 2026-08-28 —
sglang sglang/openai/structured Experimental documented 2026-08-28 —

LM Studio GGUF shares llama.cpp grammar constants and keeps its own evidence URL. MLX uses Outlines and does not copy those limits. There is no short lmstudio alias: format is required. vLLM and SGLang accept documented response_format.json_schema; they do not copy OpenAI-strict required-all. Discovery for those servers is --url / --runtime only.

Cohere, Groq, and Together are planned. New providers are data: add a target profile, fixtures, and expected diagnostics.

Request compatibility

compile() makes a schema provider-safe. It does not inspect model, endpoint, or reasoning_effort. Use checkRequest() for those combinations.

GPT-5.6 on Chat Completions rejects function tools unless effective reasoning is none. Omitting reasoning_effort still fails because the model default is medium. Responses accepts tools with reasoning.

import { checkRequest } from "llm-abi";

const result = checkRequest({
  provider: "openai",
  model: "gpt-5.6-terra",
  endpoint: "chat-completions",
  tools: true,
});

result.coverage;
// "profiled"
result.compatibility;
// "unsupported"
result.effective.reasoningEffort;
// "medium"  (model default)
result.fixes;
// [{ preferred: true, endpoint: "responses", ... }, { reasoningEffort: "none", ... }]

checkRequest() does not send the request or rewrite it. If no request profile matches, coverage is unknown. That is unchecked, not safe to send.

Runtime compatibility

checkDeployment() answers whether a contract can hold on a runtime × engine × model. It reuses compile() when the schema engine is known. It does not generate, route, or load models.

import { checkDeployment } from "llm-abi";

const result = checkDeployment({
  schema,
  deployment: {
    runtime: { kind: "lmstudio", apiSurface: "openai", engine: { kind: "llamacpp" } },
    model: { id: "Qwen3.8-27B-Q4_K_M", format: "gguf" },
  },
  request: { endpoint: "chat-completions", structuredOutput: true, tools: true },
});

Ollama Responses with stateful: true is unsupported. LM Studio without format does not guess GGUF vs MLX. Node discovery, matrix, lock/diff, and smoke/full probe are import { discoverLocalDeployments } from "llm-abi/local". Locks omit URLs, secrets, and absolute paths. Probe success does not upgrade static compatibility.

CLI

npx llm-abi check schema.json
npx llm-abi compile schema.json --target anthropic
npx llm-abi explain schema.json --target gemini
npx llm-abi analyze schema.json
npx llm-abi request request.json
npx llm-abi doctor
npx llm-abi local doctor
npx llm-abi local check schema.json
npx llm-abi local probe --suite smoke
npx llm-abi local matrix schema.json
npx llm-abi local lock schema.json
npx llm-abi local diff llm-abi.local.lock.json

--ci exits with status 1 when any target is unsupported.

GitHub Action

The reusable Action checks schema files changed by a pull request. It writes a job summary and can update one pull request comment with fingerprint and compatibility changes against the base branch.

name: Schema compatibility

on:
  pull_request:
    paths:
      - "schemas/**/*.json"

permissions:
  contents: read
  pull-requests: write

jobs:
  llm-abi:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
          persist-credentials: false
      - uses: jammaru/[email protected]
        with:
          schema-files: "schemas/**/*.json"
          comment: "true"

Pin the Action to a release tag (current: @v0.5.0). Do not use @latest. The compatibility check fails only when a current target is unsupported. Invalid input or an Action runtime failure uses exit status 2. Pull requests from forks still run the check, but GitHub may restrict their token to read-only; in that case the Action leaves the job summary and skips the comment without changing the compatibility result.

Nightly live checks

A scheduled workflow sends compiled schemas to OpenAI, Anthropic, and Gemini when repository secrets exist. It never runs on pull requests. Missing secrets skip that vendor. Outcomes are accepted, rejected, or skipped — never a percentage. Every run uploads a timestamped live-conformance.json artifact with fixture × target outcomes. A rejection means the live API disagreed with the profile; mark evidence empirical and add a fixture.

Guarantees

llm-abi does:

  • Compile one schema into a provider-safe schema
  • Tell you exactly what was rewritten, stripped, or moved to runtime validation
  • Check request combinations (model, endpoint, tools, reasoning) before a provider 400
  • Keep compile() and checkRequest() pure: no network, no filesystem, no clocks, no hidden config
  • Keep provider and request profiles versioned with the package

llm-abi does not:

  • Guarantee identical validation results across every model
  • Claim support for every model hosted on every gateway
  • Replace OpenAI, Anthropic, Gemini, or Vercel AI SDK

See docs/guarantees.md, docs/api.md, and docs/cli.md.

How it works

JSON Schema / Standard Schema / TypeScript type subset
            ↓
      Normalized IR
            ↓
 Analyze → Lower → Emit
            ↓
 Provider schema + diagnostics + fingerprint + size + validate()

Request → profile defaults → rules → compatibility + fixes

Provider differences live in profiles, not scattered if (provider === "anthropic") branches.

Repository

packages/core          compiler + CLI (published as llm-abi)
packages/conformance   fixture corpus and secret-gated live runner
packages/playground    browser compatibility playground
examples/              copy-paste SDK recipes (no network, no core SDK deps)

Contributing

See CONTRIBUTING.md. Adding a provider should be a profile file, fixtures, and tests — not a rewrite of the compiler.

Documentation

Published at llm-abi.pages.dev/docs (English) and llm-abi.pages.dev/docs/ja (日本語):

Source markdown lives in docs/ (English) and docs/ja/ (日本語). Contributor checklists stay in the repo:

License

MIT © jammaru

Releases

Packages

Contributors

Languages