> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.milliseconds.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.milliseconds.ai/_mcp/server.

# Patterns

A capability returns one decision. A pattern turns that decision into behaviour in your code.

Each page below states the problem, the wiring, and the numbers you branch on. Every page carries curl, Python and TypeScript.

## Pick a pattern by the problem

| Pattern                                               | The problem it removes                                                                   | What it buys                                                          |
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Confidence routing](/patterns/confidence-routing)    | One threshold decides everything, so cheap actions block and risky actions slip through. | A band per action: act, confirm, review, escalate.                    |
| [LLM guardrails](/patterns/llm-guardrails)            | Prompt-based safety checks cost a full LLM call on every message.                        | One batched yes-no call on the way in, and one on the way out.        |
| [Extract, then verify](/patterns/extract-then-verify) | Extracted fields land in your database with nothing to back them.                        | A second opinion per field, plus the spans that support it.           |
| [Cascade to an LLM](/patterns/cascade)                | Every input pays large-model latency, even the obvious ones.                             | The cheap decision first, the large model only for uncertain cases.   |
| [Composite scoring](/patterns/composite-scoring)      | One broad judgment hides why the score moved.                                            | Atomic rate calls with weights you own and can audit.                 |
| [Intent routing](/patterns/intent-routing)            | A router prompt drifts, and its output needs parsing.                                    | One classify call with described labels, and probabilities per route. |

## The patterns

#### [Confidence routing](/patterns/confidence-routing)

Read probability and confidence as two axes. Raise the bar with the blast radius of the action.

#### [LLM guardrails](/patterns/llm-guardrails)

Screen every message into and out of an LLM app: jailbreak, harmful request, self-harm, medical advice, urgency.

#### [Extract, then verify](/patterns/extract-then-verify)

Extract a record, then check each critical field against the source text before you write it.

#### [Cascade to an LLM](/patterns/cascade)

Answer the easy cases with one decision call. Send only the uncertain ones to a large model.

#### [Composite scoring](/patterns/composite-scoring)

Split a broad judgment into several rate calls. Weight them in your own code.

#### [Intent routing](/patterns/intent-routing)

Classify the user turn over described labels, then dispatch to a tool, an agent, or a queue.

## What every pattern assumes

Three facts drive all six patterns.

1. A decision returns a number, not prose. You branch on `probability` or `confidence` instead of parsing text, as [decisions and probabilities](/concepts/decisions-and-probabilities) describes.
2. A batch costs one HTTP request. `texts` takes up to 32 inputs, but each text is a separate model call. `statements` and `questions` batch inside one text in one inference call, and each adds only its own length to the billed input, under [batching](/capabilities/batching).
3. The thresholds are yours. The API never decides for you what is confident enough. Pick the bands on [thresholds and confidence routing](/concepts/thresholds).

> **Note**
>
> Every code sample on these pages needs an API key. Send it as `Authorization: Bearer test_sk-...`. See [Authentication](/authentication).

## Patterns and recipes

A pattern is a shape you apply to your own problem. A [recipe](/recipes/overview) is a finished job with a schema, labels, and thresholds already chosen. A recipe combines the patterns above.

## Next

* [Confidence routing](/patterns/confidence-routing) is the base that the other five build on.
* [Thresholds and confidence routing](/concepts/thresholds) explains the bands before you write code.
* [Recipes](/recipes/overview) applies these patterns to concrete jobs.