# `Dsxir.Adapter.Json`

Json adapter: instructs the LM to return a structured object validated against
the signature's output Zoi schema, and parses the returned map through that
schema directly.

Unlike `Dsxir.Adapter.Chat`, this adapter consumes a map produced by the
underlying provider's structured-output endpoint via
`Dsxir.LM.generate_object/3`. Streaming is not supported with structured
outputs; passing `:stream` in `opts` raises
`Dsxir.Errors.Invalid.Configuration`.

Returns `{:ok, map}` on success or `{:error, %Dsxir.Errors.Adapter.* {}}` on
schema validation failure. No fallback to other adapters happens here.

## One-shot schema-mismatch retry

When the provider returns an object that fails Zoi validation, the adapter
retries once with a corrective user message appended that quotes the
validation error. A second failure surfaces a
`Dsxir.Errors.Adapter.FallbackExhausted{from: __MODULE__, to: __MODULE__,
last_error: err}` via `format_and_call/4`'s `{:fallback, err}` return — the
predictor's rescue path then raises it. Subscribers tell schema-retry
exhaustion apart from Chat→Json exhaustion by reading `from`/`to`. The retry
is internal to this module.

# `output_schema`

```elixir
@spec output_schema(Dsxir.Adapter.signature()) :: Zoi.schema()
```

Build a `Zoi.object/1` schema from the signature's declared outputs.

Used by predictors to feed the schema into `Dsxir.LM.generate_object/3`.

---

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