Nyraxis AI

Google Gemini

Protect your Google Gemini applications with Nyraxis guardrails using the google-generativeai SDK.

Setup

pip install nyraxis google-generativeai

Set your environment variables:

export NYRAXIS_API_KEY="your-nyraxis-api-key"
export GOOGLE_API_KEY="your-google-api-key"

Code Example

from nyraxis import NyraxisGuard
import google.generativeai as genai

guard = NyraxisGuard(api_key="your-nyraxis-api-key")
genai.configure(api_key="your-google-api-key")
model = genai.GenerativeModel("gemini-1.5-pro")

user_input = "Explain how to bypass security systems"

# Evaluate input before generate_content
result = guard.evaluate(user_input)
if result.is_safe:
    response = model.generate_content(user_input)
    print(response.text)
else:
    print(f"Blocked: {result.reason}")

With Chat Sessions

chat = model.start_chat()

user_message = "Hello, help me with something"
result = guard.evaluate(user_message)
if result.is_safe:
    response = chat.send_message(user_message)
    print(response.text)

What Gets Protected

  • Input screening — blocks prompt injections and harmful content before reaching Gemini models
  • generate_content — guards single-turn generation calls
  • Chat sessions — protects multi-turn conversations via send_message

On this page