Turn a prompt into a reliable program
You describe what goes in and what must come out, so your app stops parsing model prose. Ax turns that contract into the prompt and validation loop.
Worked example
See the idea in context
const classify = ax('review:string -> sentiment:class \"positive, negative, neutral\"');- Name the input
review is the value your application supplies.
- Constrain the output
sentiment can only be one of the three declared classes.
- Keep the contract reusable
The same program can be tested, traced, and improved without changing its call site.
Run itIn your own project
npm install @ax-llm/ax
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 result = await classify.forward(llm, {
review: 'Useful and boring in the best way.',
});Set OPENAI_APIKEY in your environment before running provider-backed code.
From a clone of the ax repo:
npm run example -- typescript src/examples/typescript/generation/structured.tsActive practice
Answer 2 in a row to learn this · attempt 1