Nyraxis AI

Cohere

Add Nyraxis guardrails to your Cohere-powered applications using the cohere SDK.

Setup

pip install nyraxis cohere

Set your environment variables:

export NYRAXIS_API_KEY="your-nyraxis-api-key"
export CO_API_KEY="your-cohere-api-key"

Code Example

from nyraxis import NyraxisGuard
import cohere

guard = NyraxisGuard(api_key="your-nyraxis-api-key")
co = cohere.Client(api_key="your-cohere-api-key")

user_input = "Generate a phishing email template"

# Evaluate before calling Cohere
result = guard.evaluate(user_input)
if result.is_safe:
    response = co.chat(
        model="command-r-plus",
        message=user_input
    )
    print(response.text)
else:
    print(f"Blocked: {result.reason}")

With Generate

result = guard.evaluate(prompt)
if result.is_safe:
    response = co.generate(model="command-r-plus", prompt=prompt)
    print(response.generations[0].text)

What Gets Protected

  • Input screening — blocks prompt injections and harmful requests before reaching Cohere models
  • Chat and generate — guards both chat() and generate() call patterns
  • Policy enforcement — ensures all prompts comply with your configured safety policies

On this page