ReturnError
ReturnError attaches an error message to the answer's metadata whenever it receives input.
ReturnError is particularly useful in pipelines designed to detect prompt injection. You can use it together with a QueryClassifier. The pipeline starts with the QueryClassifier, which categorizes queries into genuine queries and prompt injections. When a query is identified as a prompt injection, it's redirected to the branch with the ReturnError node. This node generates an error message and attaches it to the answer's metadata. This message is visible in the search API. The pipeline ends at this point, ensuring the prompt never reaches the PromptNode. Users see an automatically generated message saying no answer was found.
If a query is classified as genuine, it's sent further down the pipeline to the branch with PromptNode.
Basic Information
- Pipeline type: Used in query pipelines
- Nodes that can precede it in a pipeline: Used after QueryClassifier
- Nodes that can follow it in a pipeline: Used as the last node in the branch.
- Input: Query, error message
- Output: Answer (with the error message added to its metadata)
- Available node classes: ReturnError
Usage Example
Here's how to use ReturnError in a pipeline. ReturnError takes output_2 of QueryClassifier (the output classified as "INJECTION"), and if it receives it, it attaches an error message informing that there has been a prompt injection attempt to the answer's metadata.
components:
- name: DocumentStore
type: DeepsetCloudDocumentStore
params:
embedding_dim: 768
similarity: cosine
- name: QueryClassifier
params:
model_name_or_path: deepset/deberta-v3-base-injection
labels: ['LEGIT','INJECTION']
type: TransformersQueryClassifier
- name: ErrorNode
type: ReturnError
params:
error_message: "Prompt injection detected. No response is generated."
...
pipelines:
- name: query
nodes:
- name: QueryClassifier
inputs: [Query]
- name: EmbeddingRetriever
inputs: [QueryClassifier.output_1]
- name: BM25Retriever
inputs: [QueryClassifier.output_1]
- name: ErrorNode
inputs: [QueryClassifier.output_2]
- name: JoinResults
inputs: [BM25Retriever, EmbeddingRetriever]
- name: Reranker
inputs: [JoinResults]
- name: PromptNode
inputs: [Reranker]
...
Parameters
Here are the parameters you can pass to ReturnError in pipeline YAML:
Parameter | Type | Possible Values | Description |
---|---|---|---|
error_message | String | The error message to return. Mandatory. |
Updated 8 months ago