DSPy for TypeScript: typed LLM contracts without prompt engineering
It compiles type signatures into LLM prompts at runtime so you stop hand-writing JSON schemas for every provider.

What it does
Ax ports the DSPy programming model to TypeScript. You declare a signature—via a string DSL, a fluent f() builder, or any Standard Schema v1 validator such as Zod—and the library compiles it to a prompt at runtime, executes the call across any of 15-plus providers, parses the streaming response, and returns a fully typed value. The same signature drives simple extraction, multi-turn agents, or sandboxed tool use without rewriting prompts.
The interesting bit
Streaming is the default, which lets Ax validate fields as they arrive, abort early when an output is already invalid, and retry without wasting tokens on a complete bad response. The hot path is intentionally thin—render, call, parse, return—so the overhead stays close to direct provider SDK calls.
Key highlights
- Provider-agnostic: one signature swaps between OpenAI, Anthropic, Google Gemini, Mistral, Ollama, and others with no prompt changes.
- Typed end-to-end: Zod, Valibot, and ArkType work at field or object level, with constraints like
.min()or.regex()feeding an automatic retry pipeline. - AxAgent runs a three-stage distiller → executor → responder loop, using a sandboxed JS runtime and checkpointed context to keep long documents from unboundedly inflating the prompt.
- Multimodal inputs and audio outputs are first-class, including realtime voice chat via WebSocket and batch transcription or synthesis.
- Runs in Node.js, Bun, Deno, and browsers, and the library carries no external dependencies.
Verdict
Worth evaluating if you want typed, provider-portable LLM calls in TypeScript without hand-managing prompts or output parsers. Python shops can safely keep scrolling.
Frequently asked
- What is ax-llm/ax?
- It compiles type signatures into LLM prompts at runtime so you stop hand-writing JSON schemas for every provider.
- Is ax open source?
- Yes — ax-llm/ax is open source, released under the Apache-2.0 license.
- What language is ax written in?
- ax-llm/ax is primarily written in TypeScript.
- How popular is ax?
- ax-llm/ax has 2.8k stars on GitHub.
- Where can I find ax?
- ax-llm/ax is on GitHub at https://github.com/ax-llm/ax.