Skip to main content

The structured_prompt Step

structured_prompt prompts the LLM for a JSON-formatted answer that matches a schema. Bosun renders your prompt with the task context, requests a structured response, validates the result, and makes it available to downstream steps.

Key characteristics of a structured_prompt step:

  • Schema-driven output: The returns field tells Bosun what shape the reply should have. Bosun converts that into a JSON Schema before calling the LLM.
  • Template support: Like every string field, the prompt accepts Tera syntax so you can inject inputs, previous outputs, or loop variables.
  • Typed outputs: When a primitive return type is used, Bosun unwraps the value wrapper for you, so outputs.<id> yields the plain string/number/boolean/array.

Choosing a return type

You can keep things simple with a primitive return type or provide a full JSON Schema when you need strongly shaped data.

Primitives

Set returns to one of string, integer, number, boolean, string_array, integer_array, or boolean_array. If you omit returns, it defaults to string.

Example:

  - id: shortlist_features
structured_prompt:
prompt: |
List three feature highlights for {{ inputs.product_name }}.
returns: string_array

The resulting array is available directly as outputs.shortlist_features for later steps.

Custom schemas

When you need richer structure, replace returns with an inline JSON Schema snippet. Bosun forwards the schema to the LLM and preserves the entire JSON object in outputs.

  - id: release_notes
structured_prompt:
prompt: |
Draft release notes for version {{ inputs.version }} with clear headings and bullet points.
returns:
type: object
required: [summary, highlights]
additionalProperties: false
properties:
summary:
type: string
highlights:
type: array
items:
type: string

With this configuration, the LLM must return an object containing summary and highlights, making the result easy to feed into other steps or tooling.

Referencing the output

Just like other steps, the response is stored under the step index and optional id. For example, {{ outputs.release_notes.highlights }} gives you quick access to the generated list inside subsequent templates.

Error handling

Structured prompts stop the task when templating fails, the LLM errors, or the response fails schema validation—unless you set continue_on_error: true. With the flag enabled, Bosun records the failure (including any schema mismatch details) and keeps the task running so follow-up steps can inspect errors.<step>. Read Error handling for more context.