# `LlmCore.Structured`
[🔗](https://github.com/fosferon/llm_core/blob/v0.3.0/lib/llm_core/structured.ex#L1)

Utilities for extracting structured data from LLM responses.

Provides lightweight JSON-mode extraction and schema validation so
consuming applications can request structured output without pulling
in heavy dependencies like Instructor.

## Supported Formats

  * `{:json_schema, schema}` — Decode JSON from the response, validate against a schema map
  * `{:json_schema, schema, opts}` — Same, with custom validator and options
  * `{:custom, fun}` — Apply a custom extraction function `(Response.t() -> {:ok, term()} | {:error, term()})`

## Usage

Structured output is typically requested via `response_format` in the dispatch opts:

    {:ok, response} = LlmCore.send(prompt, :extraction,
      response_format: {:json_schema, %{type: "object", properties: %{name: %{type: "string"}}}}
    )

    response.structured
    #=> %{"name" => "value"}

Or process a response directly:

    {:ok, response} = Structured.process({:ok, raw_response}, {:json_schema, schema})

## Custom Validators

    {:json_schema, schema, validator: fn value ->
      if value["score"] > 0.5, do: {:ok, value}, else: {:error, "score too low"}
    end}

# `response_format`

```elixir
@type response_format() ::
  {:json_schema, term()}
  | {:json_schema, term(), keyword()}
  | {:custom, (LlmCore.LLM.Response.t() -&gt; {:ok, term()} | {:error, term()})}
```

# `process`

```elixir
@spec process(
  {:ok, LlmCore.LLM.Response.t()} | {:error, term()},
  response_format() | nil
) ::
  {:ok, LlmCore.LLM.Response.t()} | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
