Skip to content

Structured Output

Define outputs in a prompt when the model should return data matching a known shape.

outputs:
- name: city
kind: string
- name: temp
kind: integer

When outputs is defined, processors can return a StructuredResult: a dictionary/object-shaped value that also keeps the raw JSON string for efficient typed casting.

Deserialize a processed structured result to an application type.

from dataclasses import dataclass
from prompty import cast
@dataclass
class Weather:
city: str
temperature: int
weather = cast(result, Weather)

Some runtimes provide generic invocation helpers that run the prompt and cast the final result in one step.

weather = invoke(
"weather.prompty",
inputs={"city": "Seattle"},
target_type=Weather,
)

For output schema data shapes, see Property and Prompty.