Quick Start

Build your first LLM program and compile it in under 5 minutes.

1. Define a Schema

Schemas define the input/output contract for your LLM program using Zod for type safety:

import { defineSchema, z } from "@mzhub/promptc";

const NameExtractor = defineSchema({
  description: "Extract proper names of people from text",
  inputs: { 
    text: z.string() 
  },
  outputs: { 
    names: z.array(z.string()) 
  }
});

2. Create a Provider

Create an LLM provider to handle API calls:

import { createProvider } from "@mzhub/promptc";

const provider = createProvider("openai", {
  apiKey: process.env.OPENAI_API_KEY
});
Supported Providers
PromptC supports OpenAI, Anthropic, Google Gemini, Groq, Cerebras, and Ollama (local).

3. Create a Program

Programs define how your LLM should execute. Use ChainOfThought for step-by-step reasoning:

import { ChainOfThought } from "@mzhub/promptc";

const program = new ChainOfThought(NameExtractor, provider);

4. Run the Program

Execute your program with input:

const result = await program.run({
  text: "Bill Gates founded Microsoft with Paul Allen."
});

console.log(result.result.names);
// ["Bill Gates", "Paul Allen"]

console.log(result.trace.reasoning);
// "The text mentions two people: Bill Gates who founded 
//  Microsoft, and Paul Allen who co-founded it with him."

5. Complete Example

Here's the full code in one file:

quick-start.js
import { 
  defineSchema, 
  ChainOfThought, 
  createProvider, 
  z 
} from "@mzhub/promptc";

// 1. Define schema
const NameExtractor = defineSchema({
  description: "Extract proper names of people from text",
  inputs: { text: z.string() },
  outputs: { names: z.array(z.string()) }
});

// 2. Create provider
const provider = createProvider("openai", {
  apiKey: process.env.OPENAI_API_KEY
});

// 3. Create program
const program = new ChainOfThought(NameExtractor, provider);

// 4. Run it
const result = await program.run({
  text: "Elon Musk runs Tesla and SpaceX."
});

console.log("Names found:", result.result.names);
console.log("Reasoning:", result.trace.reasoning);
Next Steps
This example uses a single prompt. To automatically optimize your prompts using examples, continue to the Compilation guide.