Nyraxis AI

AWS Bedrock

Add Nyraxis guardrails to AWS Bedrock models including Claude, Titan, and Llama using boto3.

Setup

pip install nyraxis boto3

Set your environment variables:

export NYRAXIS_API_KEY="your-nyraxis-api-key"
export AWS_ACCESS_KEY_ID="your-aws-key"
export AWS_SECRET_ACCESS_KEY="your-aws-secret"
export AWS_DEFAULT_REGION="us-east-1"

Code Example

import json
from nyraxis import NyraxisGuard
import boto3

guard = NyraxisGuard(api_key="your-nyraxis-api-key")
bedrock = boto3.client("bedrock-runtime")

user_input = "How do I create a weapon?"

# Evaluate input before invoke_model
result = guard.evaluate(user_input)
if not result.is_safe:
    print(f"Blocked: {result.reason}")
else:
    # Claude
    response = bedrock.invoke_model(
        modelId="anthropic.claude-3-sonnet-20240229-v1:0",
        body=json.dumps({"anthropic_version": "bedrock-2023-05-31",
            "messages": [{"role": "user", "content": user_input}], "max_tokens": 1024})
    )

    # Titan
    response = bedrock.invoke_model(
        modelId="amazon.titan-text-express-v1",
        body=json.dumps({"inputText": user_input,
            "textGenerationConfig": {"maxTokenCount": 1024}})
    )

    # Llama
    response = bedrock.invoke_model(
        modelId="meta.llama3-70b-instruct-v1:0",
        body=json.dumps({"prompt": user_input, "max_gen_len": 1024})
    )

    output = json.loads(response["body"].read())
    print(output)

What Gets Protected

  • Input screening — blocks harmful prompts before they reach any Bedrock model
  • Multi-model support — same guardrail works across Claude, Titan, and Llama
  • invoke_model — protects all calls regardless of model-specific payload format

On this page