Skip to content

draft_prompt

draft_prompt generates a candidate extract_df prompt from a plain-English goal description. It sends a one-shot meta-prompt to any supported LLM and returns a prompt string in the house style that extract_df expects: numbered step-by-step instructions, a strict {"all_results": [...]} JSON envelope, and a closing field-list sentence.

The result is a starting point. Read it, edit field names, tighten type constraints, and then pass the edited string to extract_df(prompt=...).

Draft an extract_df prompt from a plain-English goal.

draft_prompt(goal=...) sends a one-shot meta-prompt to an LLM and returns a candidate prompt string in the house style that extract_df expects: numbered step-by-step instructions, a strict Return a JSON object with this EXACT structure: {"all_results": [...]} block, and a closing "do not include any other fields" line.

The output is a starting point. Read it, edit field names, tighten type constraints, then pass to extract_df(prompt=...).

Example

from lmsyz_genai_ie_rfs import draft_prompt, extract_df p = draft_prompt( ... goal="extract the firm's stated values and a 1-5 risk-tone score", ... api_key="sk-...", ... )

... edit p ...

out = extract_df(df, prompt=p, cache_path="run.sqlite", model="gpt-4.1-mini", ... api_key="sk-...")

draft_prompt(goal: str, *, backend: str = 'openai', model: str = 'gpt-4.1-mini', api_key: str | None = None, base_url: str | None = None, print_prompt: bool = True) -> str

Draft a candidate extract_df prompt from a plain-English goal.

Sends a one-shot meta-prompt to model and returns the prompt text. The result is a starting point; read it and edit before running extract_df.

Parameters:

Name Type Description Default
goal str

Plain-English description of what to extract or measure.

required
backend str

"openai" or "anthropic".

'openai'
model str

Model identifier for the meta-call (defaults to gpt-4.1-mini; any chat model works).

'gpt-4.1-mini'
api_key str | None

Override the API key from environment.

None
base_url str | None

OpenAI base-URL override (for OpenRouter, Gemini compat).

None
print_prompt bool

When True, print the result to stdout so a notebook user sees it without an extra print call.

True

Returns:

Type Description
str

Prompt string ready to edit and pass to extract_df(prompt=...).


See also

  • extract_df: the primary extraction entry point that consumes the prompt produced here.
  • Prompts and schemas: house-style rules that draft_prompt enforces automatically.