Output Structure

Model steps produce a structured output with specific properties:

interface ModelStepOutput {
  message: string | object; // Response from the model
  model: string; // Name of the model used
  refusal?: string; // Present if model refused to respond
  raw?: {
    // Additional model metadata
    usage?: {
      prompt_tokens: number;
      completion_tokens: number;
      total_tokens: number;
      // ...
    };
    system_fingerprint?: string;
    // Other provider-specific data
  };
}

JSON Response

When Response is set to JSON in the model step configuration, the model’s response is automatically parsed into a JavaScript object:

So, you can access the properties directly from the output object in subsequent steps, without needing to use JSON.parse().

In code steps:

CODE_STEP
const { analysis, confidence } = MODEL_STEP.output.message;
console.log(analysis); // String containing analysis
console.log(confidence); // Number between 0-1

For non-code steps like model messages, http request URLs, request bodies, and other configuration fields:

{{MODEL_STEP.output.message.analysis}}
{{MODEL_STEP.output.message.confidence}}

Common Patterns

CODE_STEP
// 1. Basic text response
const textResponse = MODEL_STEP.output.message;

// 2. JSON response (with Response set to JSON)
const { analysis, score, categories } = MODEL_STEP.output.message;

// 3. Accessing metadata
const modelUsed = MODEL_STEP.output.model;
const tokenUsage = MODEL_STEP.output.raw?.usage?.total_tokens;

// 4. Checking for refusals
if (MODEL_STEP.output.refusal) {
  console.log(`Model refused: ${MODEL_STEP.output.refusal}`);
}