Repository navigation
docs: add TransformersPromptInjectionRouter page - #14050
davidsbatista wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| @@ -0,0 +1,136 @@ | |||
| --- | |||
| title: "TransformersPromptInjectionRouter" | |||
There was a problem hiding this comment.
Could we also add this page, the routers table row, and the Guardrails section to versioned_docs/version-3.5/, plus the entry in versioned_sidebars/version-3.5-sidebars.json? Otherwise it won't show up in the 3.5 docs. See #14007 for the same pattern.
|
|
||
| By default, the component raises an exception if classification fails. Set `on_error="injection"` to route the messages to `injection` instead, so that a failure never lets unchecked messages through. The error is added to the `prompt_injection_error` field in the `meta` of the checked messages. | ||
|
|
||
| Authentication with a Hugging Face API token is only required to access private or gated models. You can pass the token at initialization with `token`, or set the `HF_API_TOKEN` or `HF_TOKEN` environment variable. |
There was a problem hiding this comment.
Lets move the token paragraph out of "Handling errors", maybe into its own short "Authentication" section or just before the API reference line. It isn't related to error handling.
… guardrails section
|
|
||
| ### Prompt injection | ||
|
|
||
| A prompt injection is text that tries to override the model's instructions, such as "Ignore all previous instructions". Put a [`TransformersPromptInjectionRouter`](../pipeline-components/routers/transformerspromptinjectionrouter.mdx) in front of a chat generator or an Agent. It checks the messages with a Hugging Face model trained to detect prompt injections, sends benign messages on, and routes injections to a separate output. To catch indirect injections, it can also check tool results, such as fetched web pages. |
There was a problem hiding this comment.
Placed in front of an Agent, I believe the router only sees the messages passed into the Agent, so tool results the Agent fetches during its run never reach it. Could we say where the router needs to sit to check tool results, or drop the indirect-injection sentence here? WDYT? (Same in version-3.5.)
There was a problem hiding this comment.
I've dropped the last sentence:
"To catch indirect injections, it can also check tool results, such as fetched web pages."
|
|
||
| ### Checking tool results | ||
|
|
||
| Tool results, such as fetched web pages or search results, can contain indirect prompt injections. To check them, include `ChatRole.TOOL` in `roles`. With the default `last_message_only=True`, the component checks the last tool result and all the tool results right before it, so every result of parallel tool calls is checked. |
There was a problem hiding this comment.
Could we add a sentence on where the tool messages come from in this setup? In front of an Agent the router only gets the incoming history, not the tool results produced during the Agent's run. (Same in version-3.5.)
There was a problem hiding this comment.
I've added this sentence:
"The component only checks the messages it receives, so this works when the messages you pass in already contain tool results, such as the chat history from earlier turns. It doesn't see the tool results an Agent fetches during its run."
|
|
||
| pipe = Pipeline() | ||
| pipe.add_component("injection_router", TransformersPromptInjectionRouter()) | ||
| pipe.add_component("llm", OpenAIChatGenerator()) |
There was a problem hiding this comment.
Lets use OpenAIResponsesChatGenerator here like the Guardrails page examples, including the import on line 109 and the note on line 134. (Same in version-3.5.)
|
|
||
| Authentication with a Hugging Face API token is only required to access private or gated models. You can pass the token at initialization with `token`, or set the `HF_API_TOKEN` or `HF_TOKEN` environment variable. | ||
|
|
||
| To see the full list of parameters, check out our [API reference](/reference/integrations-transformers#transformerspromptinjectionrouter). |
There was a problem hiding this comment.
Nit: the API reference line now sits under "Authentication". Lets move it to the end of the Overview, before "Checking tool results".
There was a problem hiding this comment.
thanks! It's under overview now
Related Issues
Proposed Changes:
Adds a docs page for
TransformersPromptInjectionRouter, the new router in thetransformers-haystackintegration that detects prompt injections in chat messages and routes them to abenignor aninjectionoutput.pipeline-components/routers/transformerspromptinjectionrouter.mdx, followingtransformerstextrouter.mdxHow did you test it?
Ran the "On its own" example against the default model to check the shown output.
Notes for the reviewer
transformers-haystackrelease that includes the component, otherwise the API reference link doesn't resolve.hep_availableisfalsesince the component isn't on the platform yet.