Key Value Storage Blocks
Discover how to effectively use Key-Value Storage blocks in Scout workflows to store, retrieve, and manage data efficiently. These blocks are essential for maintaining state and handling dynamic data across workflow executions.
What is key-value storage?
- Think of key-value storage as a digital filing cabinet where you store information under specific labels. Each piece of information (the "value") is stored with a unique label (the "key") that allows you to easily find and retrieve it later.- In everyday terms:- A key is like a name tag or label
- A value is the information you want to save- Together, they form a "key-value pair"
- For example, if you want to save someone's favorite color, the key might be "JohnsFavoriteColor" and the value would be "blue".
 
 
 
- In everyday terms:
Why use key-value storage in your workflows?
- Store information between different steps of your workflow
- Remember information between different workflow runs
- Create simple counters or flags
- Save user preferences or settings
- Track the state of multi-step processes
The Three Key-Value Storage Blocks in Scout
Scout offers three simple blocks for working with key-value storage:
- Key-Value Storage (Write) - Saves information
- Key-Value Storage (Read) - Retrieves saved information
- Key-Value Storage (Delete) - Removes saved information
Let's explore each one in detail!
1. The Key-Value Storage (Write) Block
- What it does- This block allows you to save information that you might need later in your workflow or in future workflow runs.
 
- How to use it- You need to provide two things:- Key - A unique label for your information (required)
- Value - The actual information you want to store (required)
 
 
- You need to provide two things:
- Practical Examples- Example 1: Storing Basic User Information- Store a customer's name for personalization:- Key: customer_name
- Value: Maria Garcia
 
- Key: 
 
- Store a customer's name for personalization:
- Example 2: Using Dynamic Values from Workflow Input- Saving user input from a form:- Key: feedback_{{inputs.ticket_id}}
- Value: {{inputs.user_feedback}}- This creates a unique key for each feedback submission based on the ticket ID.
 
 
- Key: 
 
- Saving user input from a form:
- Example 3: Storing JSON Data- Save structured information:- Key: user_profile_1234
- Value: {"name": "John Smith", "email": "john@example.com", "preferences": {"theme": "dark", "notifications": true}}
 
- Key: 
 
- Save structured information:
- Example 4: Storing Results from Previous Blocks- Save the output from an AI model for later use:- Key: summarization_{{workflow_run_id}}
- Value: {{llm_summarize.output}}
 
- Key: 
 
- Save the output from an AI model for later use:
 
Best Practices for Writing Data
- Use descriptive key names that clearly indicate what data is stored
- Add prefixes to keys for organization (e.g., user_,session_,temp_)
- Include identifiers in keys when storing multiple related items (e.g., user_123_preferences)
2. The Key-Value Storage (Read) Block
- What it does- This block retrieves information you've previously saved using the Write block.
 
- How to use it- You need to provide:- Key - The exact label you used when saving the information (required)
- Output As - The format you want the retrieved information in (optional, defaults to text)
 
 
- You need to provide:
- Output Format Options- text - Plain text (default)
- number - Numeric value
- bool - True/False value
- json - JSON data (for objects and lists)
 
- Practical Examples- Example 1: Using the Retrieved Value in a Message- After retrieving the customer name, you can use it in a message template:- Hello {{customer_name_read.output}}! Welcome back to our service.
- customer_name_readis the ID of your Read block.
 
 
- After retrieving the customer name, you can use it in a message template:
- Example 2: Reading Dynamic Keys Based on Current Input- Retrieve specific feedback using a ticket ID:- Key: feedback_{{inputs.ticket_id}}
- Output As: text- This dynamically constructs the key based on the current ticket ID being processed.
 
 
- Key: 
- Example 3: Reading JSON Data- Retrieve a stored user profile:- Key: user_profile_1234
- Output As: json- This retrieves the stored JSON object so you can access individual properties like {{user_profile_read.output.name}}or{{user_profile_read.output.name.company}}in subsequent blocks.
 
- This retrieves the stored JSON object so you can access individual properties like 
 
- Key: 
 
- Retrieve a stored user profile:
 
- Retrieve specific feedback using a ticket ID:
- Common Use Cases- Personalization: Retrieve user preferences to customize responses
- Session Management: Read session data to maintain context across interactions
- Progress Tracking: Check completion status of multi-step processes
- Configuration: Access stored settings or parameters
- Data Persistence: Retrieve previously stored calculation results
 
 
3. The Key-Value Storage (Delete) Block
- What it does- This block removes information you no longer need from the storage, helping keep your storage clean and organized.
 
- How to use it- You only need to provide:- Key - The label of the information you want to delete (required)
 
 
- You only need to provide:
- Practical Example- Example 1: Cleanup After Workflow Completion- Remove all processing data once a workflow completes:- Key: processing_{{inputs.workflow_run_id}}
 
- Key: 
 
- Remove all processing data once a workflow completes:
 
- When to Use the Delete Block- Privacy concerns: Remove sensitive user data when no longer needed
- Housekeeping: Clean up temporary values to avoid cluttering your storage
- Reset state: Clear previous states before starting a new process
- Error recovery: Remove invalid or corrupted data
- Compliance: Follow data retention policies by removing outdated information
 
Micro-Challenge:
- To practice working with key-value blocks, start by using the Key-Value Playground template to explore how they function. As an additional exercise, try adding a delete block to the workflow to see how it removes data from the key-value store.