Nyraxis AI

Haystack

Add Nyraxis as a custom component in your Haystack pipeline to guard LLM inputs.

Setup

pip install haystack-ai nyraxis
export NYRAXIS_API_KEY="your-api-key"
export NYRAXIS_PROJECT_ID="your-project-id"

Code Example

from haystack import Pipeline, component, Document
from haystack.components.generators import OpenAIGenerator
from nyraxis import Nyraxis

@component
class NyraxisGuard:
    def __init__(self):
        self.nx = Nyraxis()

    @component.output_types(prompt=str)
    def run(self, prompt: str):
        result = self.nx.evaluate(prompt)
        if result.blocked:
            raise ValueError(f"Blocked by Nyraxis: {result.reason}")
        return {"prompt": prompt}

pipe = Pipeline()
pipe.add_component("guard", NyraxisGuard())
pipe.add_component("llm", OpenAIGenerator(model="gpt-4"))

pipe.connect("guard.prompt", "llm.prompt")

response = pipe.run({"guard": {"prompt": "Explain quantum computing"}})
print(response["llm"]["replies"][0])

What Gets Protected

  • Every prompt is evaluated by Nyraxis before reaching the LLM component
  • Blocked prompts raise an exception, preventing any downstream processing
  • Works with any Haystack generator (OpenAI, Hugging Face, custom)
  • Can be placed at multiple points in complex RAG pipelines

On this page