enable_structured_output: Enable Structured Output (Provider-Agnostic)

View source: R/json_mode.R

enable_structured_outputR Documentation

Enable Structured Output (Provider-Agnostic)

Description

Turn on structured output for a model configuration. Supports OpenAI‑compatible providers (OpenAI, Groq, Together, x.ai, DeepSeek), Anthropic, and Gemini.

Usage

enable_structured_output(
  config,
  schema = NULL,
  name = "llmr_schema",
  method = c("auto", "json_mode", "tool_call"),
  strict = TRUE
)

Arguments

config

An llm_config object.

schema

A named list representing a JSON Schema. If NULL, OpenAI-compatible providers enforce a JSON object; Gemini switches to JSON mime type; Anthropic only injects a tool when a schema is supplied.

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).

Value

Modified llm_config.

When to use tags instead

For tasks where strict JSON schema is unnecessary or unsupported, consider llm_mutate() with .tags or llm_mutate_tags() for soft structured output.

See Also

disable_structured_output(), llm_parse_structured(), llm_parse_structured_col(), llm_mutate_structured(), llm_mutate_tags()


LLMR documentation built on May 22, 2026, 1:07 a.m.