Back to Step Functions

aiExtractVariables

Intermediate

Uses advanced AI to extract specific pieces of information from text or image content with high accuracy and semantic understanding.

overview

The aiExtractVariables function uses advanced AI to extract specific pieces of information from text or image content. This function excels at understanding context and can extract variables from conversational text, documents, or visual content with high accuracy.

Extracts structured data from unstructured content using AI-powered semantic analysis. The function can handle complex conversational patterns, standalone responses, and contextual information to identify and extract the exact variables you need.

Key Differentiator: This function goes beyond keyword matching to understand context and meaning, making it ideal for conversational workflows.

Key Capabilities

Semantic Understanding

Goes beyond keyword matching to understand context and meaning

Conversational Pattern Recognition

Identifies answers in multi-turn conversations and standalone responses

Image Analysis

Can extract information from images when provided with image buffers

Validation and Formatting

Automatically formats extracted data to meet specified requirements

input_parameters

Required Inputs

ParameterTypeRequiredDescription
textstringThe source text to analyze (often "${conversationContext}")
variables_to_extractarrayArray of variable definitions specifying what to extract
image_bufferbufferOptionalImage data to analyze alongside text
image_mimetypestringOptionalMIME type of the image (e.g., "image/png")

Variable Definition Structure

Each variable in the variables_to_extract array should include the following structure:

Variable Structure Example

Validation Note: Validation rules are optional but help ensure data quality and provide better user feedback when information is missing or invalid.

Expected Outputs

Success Response

Returns an object with each extracted variable as a property:

Success Output

Failure Response

When required variables are missing, the function maintains the current step and prompts for more information:

Failure Output

Usage Examples

Simple Example

Basic contact information extraction from conversation context:

Basic Contact Information Extraction

Advanced Example with Image Processing

Extracting passport information from both text and image content:

Passport Information Extraction

Best Practices

Write Clear Descriptions

The description field is crucial for accurate extraction. Be specific about what you're looking for and the expected format.

  • Be specific about what you're looking for and the expected format
  • Include context clues that help the AI understand what to extract
  • Mention expected values or formats when applicable

Use Appropriate Validation

Set validation rules that match your data requirements, but don't be overly restrictive as the AI can format data to meet reasonable expectations.

  • Set validation rules that match your data requirements without being overly restrictive
  • Provide helpful error messages that guide users on what information is needed
  • Mark variables as required only when absolutely necessary for workflow continuation

Handle Conversational Context

When extracting from conversations, the AI understands context and can identify answers that appear after questions, even if they're standalone responses.

  • AI understands context and can identify answers from conversation flow
  • Works with standalone responses even if they don't directly reference the question
  • Identifies answers that appear after questions in conversation history

Test with Variations

Test your extraction with different ways users might provide the same information to ensure robust performance.

  • Test with different ways users might phrase the same information
  • Verify extraction works with edge cases and incomplete information
  • Ensure robust performance across various conversation styles

Related Functions

These functions work well together with aiExtractVariables to create powerful data collection workflows: