format-str-prompted-generator
GitHub提供FormatStrPromptedGenerator算子的参考文档,说明如何将DataFrame多列组合为提示词模板并调用LLM生成内容,涵盖构造函数、参数限制及运行示例。
Trigger Scenarios
Install
npx skills add OpenDCAI/DataFlow-WebUI --skill format-str-prompted-generator -g -y
SKILL.md
Frontmatter
{
"name": "format-str-prompted-generator",
"description": "Reference documentation for the FormatStrPromptedGenerator operator. Covers the constructor, prompt template restrictions, placeholder-to-column mapping, actual prompt-building logic, and runnable example usage.\nUse when: one generation task needs multiple dataframe columns combined into a single prompt through a template."
}
FormatStrPromptedGenerator Operator Reference
FormatStrPromptedGenerator is DataFlow's multi-field template-based LLM
generation operator. It maps multiple dataframe columns into template
placeholders, builds one prompt per row, calls the LLM, writes the result into
output_key, persists the dataframe, and returns the output_key string.
1. Imports
from dataflow.operators.core_text import FormatStrPromptedGenerator
from dataflow.prompts.core_text import FormatStrPrompt
2. Constructor
FormatStrPromptedGenerator(
llm_serving,
system_prompt="You are a helpful agent.",
prompt_template=FormatStrPrompt(f_str_template="..."),
json_schema=None,
)
| Parameter | Required | Default | Description |
|---|---|---|---|
llm_serving |
Yes | None | LLM service object implementing generate_from_input(...) |
system_prompt |
No | "You are a helpful agent." |
System prompt passed to the serving layer |
prompt_template |
Yes in practice | FormatStrPrompt |
Must be an instantiated FormatStrPrompt(...) or a DIYPromptABC subclass instance |
json_schema |
No | None |
Optional schema forwarded to generate_from_input(...) |
Important prompt_template Notes
- The source code default is
FormatStrPrompt, which is the class object, not an instance. Because of@prompt_restrict, omittingprompt_templateentirely can raiseTypeErrorat construction time. - Passing
prompt_template=Noneis also invalid here. UnlikeBenchAnswerGenerator, this operator explicitly raises:
ValueError("prompt_template cannot be None")
- The practical safe pattern is to always pass an instantiated template:
FormatStrPrompt(
f_str_template="Title: {title}\n\nBody: {body}\n\nSummarize this article."
)
Constructing FormatStrPrompt
FormatStrPrompt(
f_str_template="{title}\n\n{body}",
on_missing="raise",
)
3. run() Signature
op.run(
storage=self.storage.step(),
output_key="generated_content",
title="title_col",
body="body_col",
)
# returns: output_key
| Parameter | Required | Default | Description |
|---|---|---|---|
storage |
Yes | None | Current operator-step storage object |
output_key |
No | "generated_content" |
Output column to write |
**input_keys |
Yes | None | Mapping from template placeholder name to dataframe column name |
Placeholder Mapping Rule
In run(...), each kwarg uses this convention:
- kwarg name = placeholder name inside
f_str_template - kwarg value = dataframe column name to read from
Example:
prompt_template = FormatStrPrompt(
f_str_template="Title: {title}\n\nBody: {body}\n\nSummarize this article."
)
generator.run(
storage=self.storage.step(),
output_key="summary",
title="headline_col",
body="article_body_col",
)
This means:
{title}is replaced withrow["headline_col"]{body}is replaced withrow["article_body_col"]
4. Actual Execution Logic
The current implementation behaves as follows:
- Read the dataframe from
storage. - Collect
need_fields = set(input_keys.keys()). - For each row, build:
key_dict = {key: row[input_keys[key]] for key in need_fields}
- Call:
prompt_text = prompt_template.build_prompt(need_fields, **key_dict)
- Append all row prompts into
llm_inputs. - Call:
llm_serving.generate_from_input(
user_inputs=llm_inputs,
system_prompt=self.system_prompt,
json_schema=self.json_schema,
)
- Write generated outputs into
dataframe[output_key]. - Persist via
storage.write(dataframe). - Return
output_key.
5. Important Rules
- Always pass an instantiated
FormatStrPrompt(...)or a compatible DIY prompt instance. - Do not omit
prompt_template, do not pass the class object, and do not passNone. - Every value in
**input_keysmust be an existing dataframe column name. - The operator does not validate template placeholders against the template string itself. If you forget to map a placeholder that appears in
f_str_template, that placeholder can remain unreplaced in the final prompt. - If you provide a placeholder name in
**input_keysthat is not used in the template, the extra value is simply unused by string replacement. - The operator adds or overwrites
output_key, and does not filter rows. - The return value is the bare
output_keystring, not a list.
6. Typical Usage
from dataflow.operators.core_text import FormatStrPromptedGenerator
from dataflow.prompts.core_text import FormatStrPrompt
prompt_template = FormatStrPrompt(
f_str_template="Title: {title}\n\nBody: {body}\n\nPlease write a concise summary."
)
generator = FormatStrPromptedGenerator(
llm_serving=self.llm_serving,
system_prompt="You are a professional editor. Write concise, informative summaries.",
prompt_template=prompt_template,
)
generator.run(
storage=self.storage.step(),
output_key="summary",
title="title",
body="body",
)
Version History
- 2e95d40 Current 2026-08-27 09:04


