In Code Steps

In code steps, input values can be accessed directly using the input object. No curly braces are required.

CODE_STEP
const searchQuery = input.search_query;
const name = input.personal_info.name;
const items = input.item_list; // Array if multiple/array enabled

In Non-Code Steps

In non-code steps like model messages, HTTP request URLs, request bodies, and other configuration fields, input values can be referenced using double curly braces.

{{input.description}}
{{input.details.categories}}
{{input.search_query}}

Accessing Configuration Fields

Configuration fields can be accessed the same way as regular input fields, using the input object. The values from both regular input fields and configuration fields are merged into a single object at runtime.

In Code Steps

Configuration values can be accessed directly:

CODE_STEP
const threshold = input.credit_score_threshold;
const categories = input.document_categories;

In Non-Code Steps

Use double curly braces to reference configuration values:

{{input.credit_score_threshold}}
{{input.document_categories}}

File Handling Fundamentals

Learn how to work with files in your workflow steps, including accessing file contents and images.

Accessing File Contents and Images

To access file contents or images, you must enable the appropriate settings in the file field settings:

Without these properties enabled, when you try to access contents or images, they will be empty.

In Model Messages

When working with file inputs in model messages, there are two ways to access the document data:

  1. Using :contents - This extracts and passes the text content of the document to the model

    {{input.document:contents}}
    
  2. Using :images - This passes the actual document images/pages to the model

    {{input.document:images}}
    

Cortex automatically handles converting the placeholders into the actual document data before sending to the model.

The :contents and :images suffixes are used only in model messages with double curly braces:

[
  {
    "role": "user",
    "content": [
      {
        "type": "text",
        "text": "Analyze this document: {{input.document:contents}}"
      },
      {
        "type": "text",
        "text": "Images of the document pages: {{input.document:images}}"
      }
    ]
  }
]

Choosing Between Contents and Images

  • Use :contents for: Long documents where cost is a concern, very simple analysis tasks
  • Use :images for: Complex documents, forms, documents with important visual elements, when accuracy is critical

In Code Steps

Use utility functions for accessing file contents and images:

CODE_STEP
const documentContents = util.getFileContents(input.document);
const documentImages = util.getFileImages(input.document);

File Content Structure

When accessing file contents, you receive an array of objects. If multiple files upload is enabled, you receive an array of arrays:

{
  id: number;
  type: string;
  content: string;
  content_as_html?: string;
  page: number;
  parent?: number;
}

Example usage for a file field with multiple uploads not enabled:

CODE_STEP
const contents = util.getFileContents(input.document);
contents.forEach((content) => {
  console.log(`Page ${content.page}: ${content.content}`);
});

Example usage for a file field with multiple uploads enabled:

CODE_STEP
const contents = util.getFileContents(input.document);
contents.forEach((fileContents, fileIndex) => {
  fileContents.forEach((content) => {
    console.log(
      `File ${fileIndex + 1}, Page ${content.page}: ${content.content}`
    );
  });
});

File Images Structure

When accessing file images, you receive an array of image URLs. The array is always one-dimensional, containing all image URLs from the file(s):

CODE_STEP
const images = util.getFileImages(input.document); // images = ['https://...', 'https://...']

To get images separated by file when multiple files are enabled:

CODE_STEP
input.document.forEach((file) => {
  const fileImages = util.getFileImages(file); // images for this specific file
  console.log('Images for file:', fileImages); // ['https://...', 'https://...']
});