Packages
liter_llm
1.8.2
1.11.2
1.11.1
1.11.0
1.10.1
1.10.0
1.9.3
1.9.0
1.9.0-rc.2
1.9.0-rc.1
1.8.2
1.8.1
1.8.0
1.7.6
1.7.5
1.7.4
1.7.3
1.7.2
1.7.1
1.6.4
1.6.3
1.6.2
1.5.1
1.5.0
1.4.1
1.4.0-rc.61
1.4.0-rc.60
1.4.0-rc.59
1.4.0-rc.58
1.4.0-rc.57
1.4.0-rc.56
1.4.0-rc.55
1.4.0-rc.53
1.4.0-rc.52
1.4.0-rc.50
1.4.0-rc.48
1.4.0-rc.47
1.4.0-rc.46
1.4.0-rc.45
1.4.0-rc.44
1.4.0-rc.43
1.4.0-rc.39
1.4.0-rc.38
1.4.0-rc.37
1.4.0-rc.36
1.4.0-rc.35
1.4.0-rc.34
1.4.0-rc.33
1.4.0-rc.32
1.4.0-rc.31
1.4.0-rc.30
1.4.0-rc.27
1.4.0-rc.26
1.4.0-rc.25
1.4.0-rc.24
1.4.0-rc.22
1.4.0-rc.21
1.4.0-rc.20
1.4.0-rc.19
1.4.0-rc.18
1.4.0-rc.17
1.4.0-rc.16
1.4.0-rc.14
1.4.0-rc.13
1.4.0-rc.11
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
1.0.0-rc.9
1.0.0-rc.8
1.0.0-rc.7
1.0.0-rc.6
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
Universal LLM API client with Rust-powered polyglot bindings.
Current section
Files
Jump to
Current section
Files
lib/liter_llm/response_format.ex
# This file is auto-generated by alef — DO NOT EDIT.
# alef:hash:b159ec7bf40f2249b9f5696d5819688bca2310a2b26cc9acae8194e6255f8b03
# To regenerate: alef generate
# To verify freshness: alef verify --exit-code
defmodule LiterLlm.ResponseFormat do
@moduledoc """
Wire format for the chat completions `response_format` field.
# Provider mapping
- **OpenAI** (and OpenAI-compatible providers): emitted verbatim as
`{"type": "json_schema", "json_schema": {...}}` per the
chat-completions spec.
- **Gemini / Vertex AI**: translated to
`generationConfig.responseMimeType = "application/json"` and
`generationConfig.responseSchema = <schema>`. The `name`,
`description`, and `strict` fields are dropped — Gemini's
structured-output API does not consume them.
- **Anthropic**: no native JSON mode. A system instruction is
prepended asking the model to respond with valid JSON.
`strict` is advisory only; callers should still validate the
returned JSON if the schema is load-bearing.
# Example
```no_run
# use liter_llm::types::{ResponseFormat, ChatCompletionRequest};
# use serde_json::json;
let request = ChatCompletionRequest {
model: "gpt-4o".into(),
messages: vec![],
response_format: Some(ResponseFormat::json_schema(
"PersonSchema",
json!({ "type": "object", "properties": { "name": { "type": "string" } } }),
)),
..Default::default()
};
# let _ = request;
```
"""
@typedoc "Wire format for the chat completions `response_format` field."
@type t :: term()
@typedoc "Plain text output (default)."
@type text :: :text
@typedoc "Output must be valid JSON object (no schema validation)."
@type json_object :: :json_object
@typedoc "Output must conform to the specified JSON schema."
@type json_schema :: %{type: :json_schema, json_schema: LiterLlm.JsonSchemaFormat.t()}
end