Thursday, October 23, 2025

Amazon Bedrock Flows Introduces Support for Inline Code Nodes in Public Preview

Share

Exploring Inline Code Nodes in Amazon Bedrock Flows

Introduction to Inline Code Nodes

Today marks an exciting milestone for AWS developers as we unveil the public preview of inline code nodes in Amazon Bedrock Flows. This innovative feature allows users to embed Python scripts directly within their workflows, effectively eliminating the need for separate AWS Lambda functions for basic logic tasks. By streamlining both preprocessing and postprocessing operations, generative AI application development becomes more accessible, paving the way for broader organizational participation.

Key Advantages

1. Simplified Preprocessing and Postprocessing

With inline code nodes, organizations can transform input data before it reaches a large language model (LLM). This could involve extracting specific fields from JSON data, formatting text, or normalizing numerical values, all without needing to set up a separate Lambda function.

In postprocessing, the feature enables operations on the outputs directly within the workflow, such as extracting entities from responses, formatting JSON for other systems, or applying business rules to the generated results.

2. Handling Complex Use Cases

Inline code also supports intricate, multi-step generative AI workflows. For those needing to call popular Python packages (like OpenCV, SciPy, or PyPDF), the inline code node provides a user-friendly environment to manage these operations effectively.

3. Builder-Friendly Environment

Developers can create and manage inline code through both the Amazon Bedrock API and the AWS Management Console. This flexibility empowers teams to build customized workflows without getting bogged down by the infrastructure complexities typically associated with Lambda functions.

4. Enhanced Observability

The user experience is further improved with the ability to trace inputs and outputs from each node. This visibility allows teams to monitor and troubleshoot workflows seamlessly.

Real-World Impact: A Case Study

Consider Thomson Reuters, a global leader in information services. They often wrestle with complex, multi-step generative AI workflows. By leveraging the inline code feature in Amazon Bedrock Flows, they have streamlined many of their tasks. Here are some key benefits they’ve experienced:

  • Simplified Flow Management: With fewer Lambda functions to maintain, Thomson Reuters can manage thousands of workflows more efficiently. This reduces operational overhead, particularly beneficial for a large user base.

  • Flexible Data Processing: Inline code capabilities allow for direct preprocessing of data and postprocessing of model responses, enabling easier integration with both internal AWS services and third-party APIs.

  • Empowered DIY Flow Creation: Users can now construct complex workflows with custom code directly in a self-service interface, eliminating the need for constant technical support.

Getting Started: Creating Flows with Inline Code Nodes

To begin utilizing inline code nodes, here’s a step-by-step guide for setting up a flow that processes music playlist requests:

Prerequisites

Before diving in, ensure you have the necessary components in place. This includes access to the Amazon Bedrock console and familiarity with basic Python programming.

Steps to Create Your Flow

  1. Access Amazon Bedrock Console:
    Navigate to the Amazon Bedrock console and select "Flows" under "Builder tools."

  2. Create a New Flow:
    Set up a new flow (for example, easy-inline-code-flow). Refer to the Amazon Bedrock documentation for detailed instructions.

  3. Add Inline Code Nodes:
    Insert your inline code nodes. For this example, we’ll create two separate nodes to handle two different prompts.

  4. Write Preprocessing Code:
    In the Preprocessing_InlineCode node, you may want to limit user requests to a maximum of 10 songs. Below is a sample Python code snippet:

    python
    import json
    def func():
    try:
    if userprompt[‘number’] > 10:
    userprompt[‘number’] = 10
    return userprompt
    else:
    return userprompt
    except Exception as e:
    return {
    "error": "Invalid input format",
    "details": str(e)
    }
    func()

  5. Add Postprocessing Logic:
    In the Postprocessing_Inline Code node, check the number of words in the generated playlist before passing it to the next prompt node (prompt_2). Here’s an example of that code:

    python
    def __func():
    cleaned_text = " ".join(playlist.split())
    word_count = len(cleaned_text.split())
    return {
    "playlist": playlist,
    "word_count": word_count
    }
    __func()

  6. Test Your Flow:
    Using a sample input such as:

    json
    {
    "genre": "pop",
    "number": 8
    }

    You can verify that the flow executes as expected. Be cautious to treat user input as untrusted and implement appropriate validation.

Observability Features

Amazon Bedrock also provides detailed node execution traces. By enabling tracing via the API, you can examine performance metrics and identify any issues during execution, making it easier to iterate and improve your flows.

Important Considerations

When utilizing inline code nodes, keep the following in mind:

  • Code runs in a secure, AWS-managed sandbox environment with no internet access.
  • The feature supports Python 3.12 and higher, accommodating a variety of scripts.
  • Each code block can be up to 4MB, supporting popular libraries like OpenCV and SciPy.
  • Each AWS account can handle up to 25 concurrent code execution sessions.

Final Thoughts

The integration of inline code nodes into Amazon Bedrock Flows transforms the workflow development landscape for generative AI applications. By reducing complexity and enabling easier data handling within a single platform, AWS is driving efficiency and innovation across organizations.

Users are encouraged to explore these capabilities in the supported AWS regions and begin crafting their generative AI solutions today! For further details, visit the official Amazon Bedrock documentation.

Read more

Related updates