Inline Code Nodes Supported by Amazon Bedrock Flows in Public Preview

Machine Learning


We look forward to today to announce a public preview of support for inline code nodes on Amazon Bedrock Flows. This powerful new feature allows you to write Python scripts directly within your workflow, reducing the need for separate AWS lambda functions for simple logic. This feature streamlines pre- and post-processing tasks (such as normalizing data and formatting responses), simplifies the development of generated AI applications, and makes them more accessible across the organization. By removing recruitment barriers and reducing maintenance overhead, inline code capabilities accelerate enterprise adoption of generated AI solutions, resulting in faster iterative cycles and wider participation in AI application building.

Organizations using Amazon Bedrock Flows can use inline code nodes to design and deploy workflows to fully build more scalable and efficient AI applications within Amazon bedrock environments, while achieving:

  • Pre-processing – Converts input data before sending to a large language model (LLM) without setting up separate Lambda functions. For example, extracting a specific field from JSON, formatting text data, or normalizing values.
  • Post-processing – Performs operations on model output directly within the flow. For example, extract entities from responses, formatting JSONs in downstream systems, or applying business rules to the results.
  • Complex Use Cases – Manage complex, multi-step generation AI workflow execution that allows you to invoke popular packages such as OpenCV, Scipy, etc. in PYPDF.
  • Builder friendly – Creating and managing inline code through both the Amazon Bedrock API and the AWS Management Console.
  • Observability – Seamless user experience with the ability to trace inputs and outputs from each node.

This post explains the benefits of this new feature and shows how to use inline code nodes in Amazon bedrock flow.

Benefits of inline code in Amazon bedrock flow

Thomson Reuters is a global information services company that provides essential news, insights and technical solutions to professionals through the legal, tax, accounting, media and corporate sectors, dealing with complex, multi-step AI use cases that require simple pre-processing and post-processing as part of their workflows. With Amazon Bedrock Flows' inline code feature, Thomson Reuters can benefit from:

  • Simplified flow management – Easily manage thousands of workflows on a large user base (over 16,000 users and 6,000 chains) with less operational overhead, reducing the need to create and maintain individual Lambda functions for each custom code block.
  • Flexible data processing – Enables direct preprocessing of data and post-processing of LLM responses before LLM calls. This includes the ability to interact with internal AWS services and third-party APIs through a single interface.
  • Create a DIY flow – Help users build complex workflows using custom code blocks through a self-service interface, without being exposed to the complexity of the underlying infrastructure or needing lambda function management.

Solution overview

The next section shows how to create a simple Amazon bedrock flow and add inline code nodes. This example shows a practical application that builds a flow to handle user requests for music playlists. This incorporates both preprocessing and post-processing of inline code nodes to handle data validation and response formats.

Prerequisites

Before implementing any new features, make sure you:

Once these components are installed, you can continue using Amazon bedrock flows with inline code capabilities for the generated AI use case.

Create a flow using an inline code node

Complete the following steps to create the flow:

  1. Select on the Amazon Bedrock console flow under Builder Tools In the navigation pane.
  2. Create a new flow, for example, a simple inline code flow. For detailed instructions on creating flows, Amazon Bedrock Flows is now available in general with increased safety and traceability.
  3. Add an inline code node. (In this example, we'll create two nodes for two separate prompts.)

Amazon Bedrock offers a variety of node types to build prompt flows. In this example, instead of calling the Lambda function in custom code for an AI-equipped application, we use an inline code node. A flow has two inline code nodes. I've expanded the sample from the documentation to create a flow at a single prompt. New node type Inline code It is located in node Tabs in the left pane.

  1. Add the code to handle with Preprocessing_InlineCode Before sending a node to a prompt node prompt_1. Python 3 is only supported at the time of writing. In this example, we check if the number of songs the user requested is 10 or more and is set to 10.

There is also a Python code editor and sample code templates for writing code.

Use the following code:

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()

  1. The PostProcessing_Inline code node checks the number of words in the response and feeds the data to the next prompt node. prompt_2.

def __func():
    # Remove extra whitespace and count
    cleaned_text=" ".join(playlist.split())
    word_count = len(cleaned_text.split())
    return{
        "playlist": playlist,     "word_count": word_count
    }
__func()

  1. Test the flow at the following prompt:
Sample input for the Flow Input node 
{
  "genre": "pop",
    "number": 8
  }

Inputs to inline code nodes (Python functions) must be treated as untrusted user input and must implement appropriate analysis, validation, and data processing.

You can see the output as shown in the following screenshot: The system also provides access to node execution traces, highlighting detailed insights about each processing step, real-time performance metrics, and issues encountered while running the flow. You can enable Traces using the API and send it to Amazon CloudWatch logs. In the API, set it enableTrace True Field with an InvokeFlow request. each flowOutputEvent In response, it is returned with a flowTraceEvent.

I now successfully create and run Amazon Bedrock flows using inline code nodes. You can also run this flow programmatically using the Amazon Bedrock API. For more information on how to configure flows with increased safety and traceability, Amazon Bedrock Flows is now available in general with increased safety and traceability.

Considerations

When using inline code nodes with Amazon Bedrock Flows, the following are important things:

  • Code runs in an AWS managed, security, sandbox environment that is not shared with anyone and does not have internet access
  • This feature supports Python 3.12 and above
  • Efficiently handles code with a binary size of up to 4 MB. This is about 4 million characters
  • Supports general packages such as OpenCV, Scipy, Pypdf
  • Supports 25 concurrent code execution sessions per AWS account

Conclusion

Integrating inline code nodes in Amazon Bedrock Flows marks a major advance in democratization of generating AI development, reducing the complexity of managing individual Lambda functions for basic processing tasks. This enhancement directly addresses the needs of enterprise customers for a more streamlined development experience, allowing developers to focus on building sophisticated AI workflows rather than managing their infrastructure.

Amazon Bedrock Flows inline codes are available in the following AWS regions: US East (N. Virginia, Ohio), US West (Oregon) and Europe (Frankfurt). To get started, open the Amazon Bedrock Console or the Amazon Bedrock API and start building the flow in Amazon Bedrock Flows. For more information, create your first flow in Amazon Bedrock and view its traces in Amazon Bedrock to track each step in the flow.

We're happy to see innovative applications building with these new features. As always, we welcome feedback via AWS Re: Amazon Bedrock or regular AWS contacts. Join the Community.aws Generate AI Builder Community to share your experiences and learn from others.


About the author

Shubhankar SumarShubhankar Sumar He is a senior solution architect at AWS and specializes in architectoring generative AI-powered solutions for enterprise software and SaaS companies across the UK. Shubhankar is a powerful background in software engineering, excels in designing secure, scalable, and cost-effective multi-tenant systems on the cloud. His expertise is to seamlessly integrate cutting-edge generator AI capabilities into existing SaaS applications, helping customers stay at the forefront of innovation.

Jesse Manders I am the senior product manager for Amazon Bedrock, an AWS Generic AI developer service. He works at the intersection of AI-human interactions and aims to create and improve generative AI products and services to meet our needs. Previously, Jesse was a senior scientist at Silicon Valley startups who served as leadership roles for the engineering team at Apple and Lumileds. He has an MS and a PhD. He was an MBA at the University of Florida, University of California, Berkeley, and the Haas School of Business.

Huong nguyenHuong nguyen I am AWS Principal Product Manager. She leads Amazon's bedrock flow and has 18 years of experience building customer-centric and data-driven products. She is passionate about democratizing responsible machine learning and generating AI to enable customer experience and business innovation. Outside of work, she enjoys spending time with family and friends, listening to audiobooks, traveling and gardening.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *