| llm_mutate_structured | R Documentation |
Drop-in schema-first variant of llm_mutate(). Produces parsed columns.
llm_mutate_structured(
.data,
output,
prompt = NULL,
.messages = NULL,
.config,
.system_prompt = NULL,
.before = NULL,
.after = NULL,
.schema = NULL,
.fields = NULL,
.validate_local = TRUE,
.rows_per_prompt = 1L,
.rowpack_payload = c("user", "system"),
.rowpack_recovery = c("halve_recursive", "halve_once", "singletons", "retry_same",
"none"),
...
)
.data |
A data.frame / tibble. |
output |
Unquoted name that becomes the new column (generative) or
the prefix for embedding columns. In shorthand form, omit this argument
and pass |
prompt |
Optional glue template string for a single user turn; reference
any columns in |
.messages |
Optional named character vector of glue templates to build
a multi-turn message, using roles in |
.config |
An llm_config object (generative or embedding). |
.system_prompt |
Optional system message sent with every request when
|
.before, .after |
Standard dplyr::relocate helpers controlling where the generated column(s) are placed. |
.schema |
Optional JSON Schema (R list). When provided, this schema is sent to
the provider for strict validation and used for local parsing. When |
.fields |
Optional character vector of fields to extract from parsed JSON. Supports:
|
.validate_local |
If TRUE (default) and |
.rows_per_prompt |
Integer scalar, or |
.rowpack_payload |
One of |
.rowpack_recovery |
How to handle rows a batched call leaves unresolved.
One of |
... |
Passed to the underlying calls: |
.data with the output column, the diagnostic columns, and the parsed
structured columns (structured_ok, structured_data, one column per
hoisted field, and structured_valid/structured_error when .schema is
validated locally).
Like llm_mutate(), this function supports shorthand syntax:
df |> llm_mutate_structured(result = "{text}", .config = cfg, .schema = schema)
df |> llm_mutate_structured(result = c(system = "Be brief.", user = "{text}"), .config = cfg, .schema = schema)
llm_mutate(), llm_fn_structured(), enable_structured_output(),
llm_parse_structured_col(), llm_mutate_tags()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.