| llm_mutate_tags | R Documentation |
Soft structured variant of llm_mutate(). It asks the model to return simple
XML-like tags, then parses those tags into columns.
llm_mutate_tags(
.data,
output,
prompt = NULL,
.messages = NULL,
.config,
.system_prompt = NULL,
.before = NULL,
.after = NULL,
.tags,
.fields = NULL,
...
)
.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. |
.tags |
Character vector of tag names to request and parse. |
.fields |
|
... |
Passed to the underlying calls: |
Returns the mutated data frame plus:
tags_okTRUE when all requested tags were found.
tags_dataA list-column of parsed tag lists.
One column per requested tag or field. Scalar columns are coerced to numeric or logical when all non-missing values allow it.
df |> llm_mutate_tags(result = "{text}", .tags = c("age", "job"), .config = cfg)
llm_mutate(), llm_parse_tags(), llm_parse_tags_col(),
llm_mutate_structured(), llm_parse_structured_col()
## Not run:
df <- tibble::tibble(city = c("Cairo", "Lima"))
cfg <- llm_config("openai", "gpt-4.1-nano", temperature = 0)
df |>
llm_mutate_tags(
geo = "Where is {city}? Give country and continent in their own tags.",
.config = cfg,
.system_prompt = paste(
"Use XML tags for different parts of the answer, but do not nest tags.",
"Return <country>...</country> and <continent>...</continent>."
),
.tags = c("country", "continent")
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.