Skip to main content
Back

Ax Brings Stanford's DSPy AI Programming to Six Languages at Once

Ax turns typed signatures into full LLM pipelines and now compiles one core into TypeScript, Python, Java, C++, Go, and Rust libraries.

  • Ax is the unofficial DSPy framework for TypeScript, now expanded across six languages.
  • Signatures declare typed inputs and outputs, and Ax generates prompts, parsers, retries, and traces automatically.
  • One AxIR compiler emits native packages for TypeScript, Python, Java, C++, Go, and Rust.
  • AxAgent runs a distiller-executor-responder loop with sandboxed JS, memories, skills, and checkpointed replay.
  • AxFlow lets you write full workflows as Mermaid diagrams with typed nodes and retry loops.
  • GEPA optimizer tunes prompts against Pareto fronts across quality, cost, and latency.

The ax-llm/ax project has quietly grown into one of the most ambitious ports of Stanford's DSPy ideas outside Python. It started as a TypeScript-first framework where you describe LLM tasks with a one-line signature and let the library handle prompting, parsing, retries, and typed output. That same programming model, from one shared core, now ships to six languages.

Ax is built around a simple bet: rather than writing prompts, you write typed contracts. A signature declares what data the model receives and what typed data your app expects back. Ax then does the plumbing that usually lives scattered across your codebase: rendering the prompt, calling the provider, parsing output, validating constraints, retrying with feedback, streaming partial results, and emitting traces.

What a signature actually buys you

The hello-world is a single line. You declare inputs, outputs, and types in a compact DSL, then call forward:

import { ai, ax } from "@ax-llm/ax";
const llm = ai({ name: "openai", apiKey: process.env.OPENAI_APIKEY });
const classify = ax(
  'review:string -> sentiment:class "positive, negative, neutral"',
);
const { sentiment } = await classify.forward(llm, {
  review: "This product is amazing!",
});

Switching the provider name from openai to anthropic, google-gemini, together, fireworks, deepseek, or grok reuses the same signature and the same call site. The name is a deployment profile: a DeepSeek model hosted by Together uses Together's endpoint and reasoning rules, not DeepSeek's native wire format. That distinction matters if you have ever tried to keep tool-calling behavior consistent across gateways.

Signatures scale from single fields to nested objects with constraints, and they interop with Standard Schema v1, so you can drop in Zod, Valibot, or ArkType validators at the field or whole-object level without writing an adapter. Streaming is the default path: fields get parsed as they arrive, assertions can fail early, and the in-flight stream is cancelled before you spend tokens on output that is already invalid.