Skip to content

Prompting and structured outputs

Prompting is not just writing instructions for a model. In a workflow, a prompt is also an interface between unstructured language and structured automation.

If the next node expects a field, list, label, or JSON object, design the prompt and output parser together.

flowchart TD
  Role["Role or perspective"] --> Task["Task"]
  Task --> Context["Input context"]
  Context --> Rules["Rules and constraints"]
  Rules --> Output["Output format"]
  Output --> Examples["Optional examples"]

A good workflow prompt usually includes:

  • The task to perform.
  • The input fields the model should use.
  • What not to do.
  • The required output format.
  • A fallback when the answer is not available.
Weak promptStronger workflow prompt
“Summarize this.”“Summarize pageText in 5 bullet points for a sales researcher. Do not include claims not present in the text.”
“Extract products.”“Return JSON with name, price, currency, and sourceUrl. If a price is missing, set price to null.”
“Is this relevant?”“Classify as relevant or not_relevant, then provide one sentence explaining the decision from the source text.”

Use structured output when another node must consume the AI result.

flowchart LR
  Text["Page text"] --> Prompt["Prompt with schema"]
  Prompt --> Model["Chat model"]
  Model --> Parser["Structured Output Parser"]
  Parser --> Next["Filter / integration / file"]

  style Parser fill:#e8f5e9,stroke:#2e7d32

Plain prose is fine for humans. JSON-like output is better for workflows.

Before writing the prompt, decide what the next node needs.

{
"companyName": "string",
"pricingMentioned": "boolean",
"price": "number or null",
"currency": "string or null",
"sourceQuote": "string"
}

Then write the prompt around that structure:

Extract pricing information from pageText. Return only the fields in the schema. If the page does not mention pricing, set pricingMentioned to false and price to null. Use a short source quote from the page when available.

Do not make the model guess silently. Give it a valid output for missing information.

SituationBetter fallback
Source does not mention a valuenull plus a reason
Classification is uncertainunknown with confidence
Retrieved context is insufficient“Not enough source information”
Tool call failsStructured error field

Test with:

  • Empty input.
  • Very long input.
  • Missing fields.
  • Conflicting source text.
  • Pages with navigation text mixed into content.
  • Non-English or unusually formatted content.