Renders every row exactly as llm_fn() / llm_mutate() would (no API call,
no file I/O), then reports a tidy, row-level summary: the rendered text, the
roles, character counts, file presence and existence, the batch plan, and a
list-column of issues. Problems that would only surface mid-run (a missing
file, a "file" role combined with .rows_per_prompt > 1, an embedding config
with row batching, .return = "object" with batching, a schema supplied
without .structured, a template that references NA values or renders an
empty prompt, a file part with no accompanying user text, or a tag name that
collides with the batched <row_N> protocol) are collected per row so you
see all of them at once rather than hitting the first error.
Usage
llm_preview(
.data,
prompt = NULL,
.messages = NULL,
.system_prompt = NULL,
.config = NULL,
.structured = FALSE,
.schema = NULL,
.tags = NULL,
.return = c("columns", "text", "object"),
.rows_per_prompt = 1L,
rows = NULL,
max_chars = 500L
)Arguments
- .data
A data.frame/tibble whose columns feed the
gluetemplates.- prompt
A single
gluetemplate string (mutually exclusive with.messages).- .messages
A character vector of
gluetemplates, optionally named by role ("system","user","assistant","file"). Unnamed entries default to"user".- .system_prompt
Optional system string, prepended when a row has no
"system"message.- .config
Optional
llm_config(). When supplied, preview checks the embedding-vs-row-batching conflict; otherwise config-dependent checks are skipped.- .structured
Logical; if
TRUE, the call would request structured JSON output. Used only to validate.schema/.tagscombinations.- .schema
Optional JSON schema (list). Flagged if supplied without
.structured = TRUE.Optional character vector of tag names. Flagged if combined with
.structured = TRUE(structured takes precedence).- .return
One of
"columns","text","object". Only used to flag the unsupported"object"+ batching combination.- .rows_per_prompt
Rows per call.
1(default) means one call per row;> 1orInfpacks rows into batched calls.- rows
Optional integer vector selecting which rows to render (default: all rows).
- max_chars
Truncate each row's rendered preview to this many characters (default 500). Set higher to see full prompts.
Value
A tibble of class llmr_preview, one row per previewed input row,
with columns: row, ok (no issues), roles, rendered_preview,
chars, has_file, file_ok, rowpack_id, rows_per_prompt, rowpack_row, and
issues (a list-column of character vectors).
Details
Batched data travels inside numbered <row_i>...</row_i> tags; the
rowpack_id / rows_per_prompt / rowpack_row columns show how rows would be
grouped into calls at the given .rows_per_prompt.
Examples
df <- data.frame(text = c("a", "b", "c"), stringsAsFactors = FALSE)
llm_preview(df, prompt = "Classify: {text}", .rows_per_prompt = 2)