| enable_structured_output | R Documentation |
Turn on structured output for a model configuration. Supports OpenAI-compatible providers (OpenAI, Groq, Together, x.ai, DeepSeek, Xiaomi, Alibaba (Qwen), Zhipu, Moonshot), Anthropic, and Gemini.
enable_structured_output(
config,
schema = NULL,
name = "llmr_schema",
method = c("auto", "json_mode", "tool_call"),
strict = TRUE
)
config |
An llm_config object. |
schema |
A named list representing a JSON Schema.
If |
name |
Character. Schema/tool name for providers requiring one. Default "llmr_schema". |
method |
One of c("auto","json_mode","tool_call"). "auto" chooses the best per provider. You rarely need to change this. |
strict |
Logical. Request strict validation when supported
(OpenAI-compatible). Strict mode has formal requirements of its own:
every object must set |
Modified llm_config.
OpenAI, Groq, Together, x.ai, and Ollama accept a strict json_schema
response format. DeepSeek, Alibaba (Qwen), Zhipu, Moonshot, and Xiaomi
accept only JSON-object mode; for them the supplied schema drives local
parsing and validation, so the prompt itself should describe the desired
fields. Anthropic enforcement runs through a forced tool call; Gemini
through responseJsonSchema.
A supplied schema is sent as responseJsonSchema (standard JSON Schema,
supported by Gemini 2.5+ models) together with the JSON mime type. For an
older model that rejects it, set gemini_enable_response_schema = FALSE in
the config to fall back to JSON-mime-type-only mode (the reply is still
parsed and can be validated locally).
For tasks where strict JSON schema is unnecessary or unsupported, consider
llm_mutate() with .tags or llm_mutate_tags() for soft structured output.
disable_structured_output(), llm_parse_structured(),
llm_parse_structured_col(), llm_mutate_structured(),
llm_mutate_tags()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.