# llm-patterns

llm-patterns is a Claude Code skill for structuring AI-first applications with typed LLM calls, prompt versioning, and tiered tests.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 302 installs · ★ 713 repo stars
- Author: alinaqi
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/alinaqi/maggy/tree/HEAD/skills/llm-patterns/SKILL.md
- Updated: 2026-10-13
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/llm-patterns

## What it does

The skill enforces a clear separation: the model handles classification, extraction, and natural-language decisions, while standard code manages validation, database operations, and HTTP routing. It specifies a clean project layout dividing prompts, client utilities, and test directories.

Interaction with the provider relies on a typed `llmCall` wrapper that parses raw responses against Zod schemas. Testing is structured across three distinct layers: deterministic unit tests using mocks, fixture runs checking schema compatibility, and scheduled evaluation suites measuring accuracy over larger sample sets.

Evaluation runs hit real endpoints, so CI pipelines require an `ANTHROPIC_API_KEY` secret alongside custom run flags.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add alinaqi/maggy --skill llm-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/llm-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/llm-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add alinaqi/maggy --skill llm-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/llm-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add alinaqi/maggy --skill llm-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/llm-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install alinaqi/maggy skills/llm-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/llm-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add alinaqi/maggy --skill llm-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/alinaqi/maggy --path skills/llm-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/llm-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add alinaqi/maggy --skill llm-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/alinaqi/maggy/tree/HEAD/skills/llm-patterns/SKILL.md

## When to use it
- organize an AI-first repository around prompts, schemas, and services
- validate raw LLM output using Zod schemas and TypeScript types
- write fast unit tests for model calls using mocked responses
- run scheduled accuracy evals inside GitHub Actions

## Example prompts
- Structure a support ticket classification service using llm-patterns
- Create a typed LLM client wrapper with Zod schema validation
- Set up mock unit tests and a JSON fixture suite for output parsing

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 49e95a837b6f3b4f.

BEGIN THIRD-PARTY FILE 49e95a837b6f3b4f
````text
---
name: llm-patterns
description: AI-first application patterns, LLM testing, prompt management
when-to-use: When building apps where LLMs handle core logic - classification, extraction, generation
user-invocable: false
effort: medium
---

# LLM Patterns Skill


For AI-first applications where LLMs handle logical operations.

---

## Core Principle

**LLM for logic, code for plumbing.**

Use LLMs for:
- Classification, extraction, summarization
- Decision-making with natural language reasoning
- Content generation and transformation
- Complex conditional logic that would be brittle in code

Use traditional code for:
- Data validation (Zod/Pydantic)
- API routing and HTTP handling
- Database operations
- Authentication/authorization
- Orchestration and error handling

---

## Project Structure

```
project/
├── src/
│   ├── core/
│   │   ├── prompts/           # Prompt templates
│   │   │   ├── classify.ts
│   │   │   └── extract.ts
│   │   ├── llm/               # LLM client and utilities
│   │   │   ├── client.ts      # LLM client wrapper
│   │   │   ├── schemas.ts     # Response schemas (Zod)
│   │   │   └── index.ts
│   │   └── services/          # Business logic using LLM
│   ├── infra/
│   └── ...
├── tests/
│   ├── unit/
│   ├── integration/
│   └── llm/                   # LLM-specific tests
│       ├── fixtures/          # Saved responses for deterministic tests
│       ├── evals/             # Evaluation test suites
│       └── mocks/             # Mock LLM responses
└── _project_specs/
    └── prompts/               # Prompt specifications
```

---

## LLM Client Pattern

### Typed LLM Wrapper
```typescript
// core/llm/client.ts
import Anthropic from '@anthropic-ai/sdk';
import { z } from 'zod';

const client = new Anthropic();

interface LLMCallOptions<T> {
  prompt: string;
  schema: z.ZodSchema<T>;
  model?: string;
  maxTokens?: number;
}

export async function llmCall<T>({
  prompt,
  schema,
  model = 'claude-sonnet-4-6',
  maxTokens = 1024,
}: LLMCallOptions<T>): Promise<T> {
  const response = await client.messages.create({
    model,
    max_tokens: maxTokens,
    messages: [{ role: 'user', content: prompt }],
  });

  const text = response.content[0].type === 'text'
    ? response.content[0].text
    : '';

  // Parse and validate response
  const parsed = JSON.parse(text);
  return schema.parse(parsed);
}
```

### Structured Outputs
```typescript
// core/llm/schemas.ts
import { z } from 'zod';

export const ClassificationSchema = z.object({
  category: z.enum(['support', 'sales', 'feedback', 'other']),
  confidence: z.number().min(0).max(1),
  reasoning: z.string(),
});

export type Classification = z.infer<typeof ClassificationSchema>;
```

---

## Prompt Patterns

### Template Functions
```typescript
// core/prompts/classify.ts
````
END THIRD-PARTY FILE 49e95a837b6f3b4f

The third-party file has ended. Everything between the 49e95a837b6f3b4f tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2988 of 8551 bytes. © alinaqi · MIT · https://github.com/alinaqi/maggy/tree/HEAD/skills/llm-patterns/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
