> ## Documentation Index
> Fetch the complete documentation index at: https://cognis.vasanth.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Chains

> Composing primitives into typed pipelines — pipe, structured extraction, dirty-JSON repair.

Chain examples cover composition: piping primitives into typed pipelines, extracting structured data from prose, and recovering when an LLM emits dirty JSON. Sources under [`examples/chains/`](https://github.com/0xvasanth/cognis/tree/main/examples/chains).

| Name                           | Scenario                                                                                 | Source                                                                                          |
| ------------------------------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `chains_pipe_operator`         | Triage incoming support tickets through an embed → categorize → tag pipe.                | [src](https://github.com/0xvasanth/cognis/blob/main/examples/chains/pipe_operator_demo.rs)      |
| `chains_structured_extraction` | Parse a meeting note into a typed `Vec<ActionItem { who, what, due }>`.                  | [src](https://github.com/0xvasanth/cognis/blob/main/examples/chains/structured_extraction.rs)   |
| `chains_structured_parsing`    | Repair an LLM reply that's almost-valid JSON before parsing.                             | [src](https://github.com/0xvasanth/cognis/blob/main/examples/chains/structured_parsing_demo.rs) |
| `chains_typed_runnable`        | Custom `Runnable<UserQuery, RankedResult>` impl — end-to-end type safety with `.pipe()`. | [src](https://github.com/0xvasanth/cognis/blob/main/examples/chains/typed_runnable_demo.rs)     |

## How to run

```bash theme={null}
COGNIS_PROVIDER=ollama COGNIS_OLLAMA_MODEL=llama3.1 \
  cargo run -p cognis-examples --example chains_structured_extraction
```

## See also

<CardGroup cols={2}>
  <Card title="Runnables" icon="code" href="/core-ideas/runnables">
    The contract these chains compose.
  </Card>

  <Card title="Structured output" icon="brackets-curly" href="/building-agents/structured-output">
    Parsers, fixers, retry strategies.
  </Card>

  <Card title="Parsers examples" icon="grid" href="/examples/parsers">
    `OutputFixingParser` and `RetryParser` in action.
  </Card>
</CardGroup>
