Haystack is a framework for building search and question-answering systems with LLMs. Its pipeline architecture, built around composable components, provides natural insertion points for safety checks. This guide shows how to add Authensor safety components to Haystack pipelines.
Haystack's component model lets you create custom nodes that integrate into any pipeline. Build an Authensor safety component that acts as a pipeline node.
The component receives input from the previous pipeline stage, sends it to Authensor for evaluation, and either passes it through or blocks it based on the policy decision. Implement it as a Haystack component with the standard run() method.
Place a safety node between the user input and the retriever. This node scans queries for prompt injection attempts and policy violations before they trigger document retrieval.
The node checks for injection patterns, validates query length against policy limits, and verifies that the user has access to the requested document collections. Blocked queries return an error response without consuming retriever or LLM resources.
After retrieval, a document safety node scans each retrieved document for prompt injection payloads and sensitive content. This prevents indirect injection attacks where malicious content has been planted in the document store.
The node can operate in filter mode (removing unsafe documents) or flag mode (annotating documents with safety metadata for downstream handling).
A final safety node checks the generated response before it reaches the user. It scans for harmful content, PII leakage, and policy violations in the model's output.
Compose the safety nodes into your pipeline alongside standard Haystack components. Place them at the boundaries where untrusted data enters or leaves the pipeline.
A typical safe pipeline flow: query safety node, retriever, document safety node, prompt builder, LLM, response safety node.
Each safety node adds latency. The query safety node and response safety node each add 2 to 10 milliseconds with regex-based scanning. The document safety node processes each retrieved document, so latency scales with the retrieval count. For a typical top-5 retrieval, expect 5 to 20 milliseconds total.
Each safety node logs its decisions to Authensor's audit trail. The pipeline execution ID links all safety decisions for a single query, giving you end-to-end visibility into safety enforcement across the pipeline.
Explore more guides on AI agent safety, prompt injection, and building secure systems.
View All Guides