llm_parse_structured: Parse structured output emitted by an LLM

View source: R/json_mode.R

llm_parse_structuredR Documentation

Parse structured output emitted by an LLM

Description

Robustly parses an LLM's structured output (JSON). Works on character scalars or an llmr_response. Strips code fences first, then tries strict parsing, then attempts to extract the largest balanced {...} or [...].

Usage

llm_parse_structured(x, strict_only = FALSE, simplify = FALSE)

Arguments

x

Character or llmr_response.

strict_only

If TRUE, do not attempt recovery via substring extraction.

simplify

Logical passed to jsonlite::fromJSON (simplifyVector = FALSE when FALSE).

Details

The return contract is list-or-NULL; scalar-only JSON is treated as failure.

Numerics are coerced to double for stability.

Value

A parsed R object (list), or NULL on failure.

See Also

llm_parse_structured_col(), llm_fn_structured(), llm_mutate_structured(), llm_parse_tags()

Examples

llm_parse_structured('{"score": 5, "label": "good"}')


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