Skip to contents

Tags-first variant of llm_fn(). Injects tag instructions, calls the model via call_llm_broadcast(), then parses XML-like tags from each response.

Usage

llm_fn_tags(
  x,
  prompt,
  .config,
  .system_prompt = NULL,
  ...,
  .tags,
  .fields = NULL,
  .return = c("columns", "text", "object"),
  .rows_per_prompt = 1L,
  .rowpack_payload = c("user", "system"),
  .rowpack_recovery = c("halve_recursive", "halve_once", "singletons", "retry_same",
    "none")
)

Arguments

x

A character vector or a data.frame/tibble.

prompt

A glue template string. With a data-frame you may reference columns ({col}); with a vector the placeholder is {x}.

.config

An llm_config object.

.system_prompt

Optional system message (character scalar).

...

Passed unchanged to call_llm_broadcast() (e.g. tries, progress, verbose).

.tags

Character vector of tag names to request and parse.

.fields

NULL to extract all tags, a character vector of tags, a named vector such as c(person_age = "age"), or FALSE to skip field extraction.

.return

One of c("columns","text","object"). "columns" returns a tibble with the parsed tag columns and diagnostics; "text" returns the raw response text. Unlike llm_fn(), "object" here returns the parsed tag data (a list, one element per row), not llmr_response objects; this form is also supported together with .rows_per_prompt > 1.

.rows_per_prompt

Integer scalar, or Inf. Number of input elements packed into a single generative request. The default, 1, sends one request per element (the historical behaviour). When greater than 1, elements are grouped and transmitted in one call wrapped in numbered <row_1>...</row_1> tags (see Row batching below); Inf sends all elements in a single call. Ignored for embedding configurations, which use get_batched_embeddings() instead.

.rowpack_payload

One of c("user","system"). Channel to which the <row_i> data block is appended when batching. The imperative instruction is always placed in the system message; this argument controls only where the data goes. The default, "user", keeps a static system prompt cacheable.

.rowpack_recovery

How to handle rows that a batched call leaves unresolved (dropped, malformed, or truncated). One of:

"halve_recursive"

(default) re-issue the unresolved rows at half the batch size, recursing down to single rows.

"halve_once"

re-issue at half the batch size exactly once, then give up on any still-unresolved rows.

"singletons"

re-issue each unresolved row on its own.

"retry_same"

re-issue the failed batch once at the same size.

"none"

do not recover; unresolved rows are returned as NA.

Recovery is bounded by an internal call budget so it always terminates.

Value

Depends on .return: "columns" (default) a tibble with the parsed tag columns and diagnostics; "text" a character vector of the raw responses; "object" a list (one element per row) of parsed tag data.