---
title: "Examples Overview"
description: "Complete, copy-paste examples of Nuabase solving real problems."
canonical: "https://nuabase.com/docs/examples/"
---

> Documentation index: https://nuabase.com/llms.txt

This section contains complete, real-world examples showing Nuabase in action. Each example includes:

- A problem description
- Complete, copy-paste ready code
- Expected output
- Variations

## Available Examples

### Lead Enrichment

Classify and prioritize sales leads based on notes and context. A classic B2B use case demonstrating `nua.list()` with complex schemas.

[View Example](/docs/examples/lead-enrichment.md)

### Sentiment Analysis

Analyze customer feedback at scale. Shows batch processing with `nua.list()` and grouping results.

[View Example](/docs/examples/sentiment-analysis.md)

### Data Extraction

Extract structured data from unstructured text. Demonstrates schema design and validation patterns.

[View Example](/docs/examples/data-extraction.md)

## Running the Examples

Install Nuabase and Zod:

```bash
npm install nuabase zod
```

The examples use whichever coding agent is installed and logged in on your machine:

```typescript
import { Nua, z } from 'nuabase';
import { findLocalAgent } from 'nuabase/local-agent';

const nua = Nua.direct({ localAgent: await findLocalAgent() });
```

To run them against an LLM API instead, swap the client:

```typescript
import { Nua, z } from 'nuabase';

const nua = Nua.direct({
  providers: { openrouter: { apiKey: process.env.OPENROUTER_API_KEY! } },
});
```

The rest of each example is the same with either client.

## Schema Design Tips

When designing schemas for your use cases:

### Keep Schemas Simple

```typescript
// Good: focused schema
const SentimentSchema = z.object({
  sentiment: z.enum(['positive', 'neutral', 'negative']),
  confidence: z.number().min(0).max(1),
});

// Avoid: overly complex schemas
const OverlyComplexSchema = z.object({
  sentiment: z.object({
    primary: z.enum(['positive', 'neutral', 'negative']),
    secondary: z.array(z.string()),
    scores: z.object({
      positive: z.number(),
      neutral: z.number(),
      negative: z.number(),
    }),
  }),
  // ... many more nested fields
});
```

### Use Enums for Classification

```typescript
// Good: constrained options
const CategorySchema = z.enum(['bug', 'feature', 'question']);

// Less reliable: free-form string
const CategorySchema = z.string();
```

### Make Optional Fields Explicit

```typescript
const ContactSchema = z.object({
  name: z.string(),
  email: z.string(),
  phone: z.string().optional(),  // Explicitly optional
  company: z.string().optional(),
});
```

### Add Validation Constraints

Every answer is parsed with your schema, and an answer that breaks a constraint is retried:

```typescript
const MetricsSchema = z.object({
  score: z.number().min(0).max(100),
  count: z.number().int().nonnegative(),
  percentage: z.number().min(0).max(1),
  zip: z.string().regex(/^\d{5}$/),
});
```

`.refine()` checks, string formats such as `z.email()`, `.default()`s, and `.transform()`s all apply to `result.data`. See [How It Works](/docs/how-it-works.md#schemas).

### Keep the Prompt Constant

Put everything that varies in `input`, not in the prompt string. Providers cache the unchanging start of each request, which makes repeated calls cheaper and faster. See [prompt caching](/docs/how-it-works.md#prompt-caching).

## Prompt Writing Tips

### Be Specific

```typescript
// Good: clear instructions
await nua.get("Classify the customer support ticket into one of the following categories: bug report, feature request, billing question, or general inquiry", options);

// Vague: leaves too much interpretation
await nua.get("Classify this", options);
```

### Provide Context

```typescript
await nua.get("You are analyzing sales leads for a B2B SaaS company. Classify each lead by their likely company size and purchase intent.", {
  input: leadNotes,
  output: { name: 'classification', schema: LeadSchema }
});
```

### Match Prompt to Schema

```typescript
const OutputSchema = z.object({
  category: z.enum(['high', 'medium', 'low']),
  reason: z.string(),
});

// Good: prompt matches schema fields
await nua.get("Rate the priority (high, medium, or low) and explain the reason", {
  output: { name: 'rating', schema: OutputSchema }
});
```
