Agent studio and askAI: `sidepanel-js: data-guardrail-violation events dropped silently; guardrail-triggered responses render as one token`
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 439
- Avg merge
- 14h 32m
- Merged PRs (30d)
- 19
Description
## Description
When an Agent Studio input guardrail fires (e.g. `off_topic_questions`), the backend emits a `data-guardrail-violation` event containing a `fallbackResponse` string. `@docsearch/sidepanel-js` has no handler for this event type, so the fallback string is dropped and the UI renders only the aborted `text-delta` chunks — typically a single letter (e.g. `"I"`).
## Steps to reproduce
1. In Agent Studio, enable a guardrail, such as `off_topic_questions` input guardrail on your assistant
2. Mount `@docsearch/sidepanel-js` with `agentStudio: true` and that assistant's ID
3. Ask an off-topic question, e.g. "What's the capital of France?"
**Raw EventStream** (verbatim from the streaming API response):
```
data: {"type": "start", "messageId": "alg_msg_tVT46Wu8tMHAe2jK", "messageMetadata": {}}
data: {"type": "start-step"}
data: {"type": "text-start", "id": "alg_msg_tVT46Wu8tMHAe2jK"}
data: {"type": "text-delta", "id": "alg_msg_tVT46Wu8tMHAe2jK", "delta": "I"}
data: {"type": "text-end", "id": "alg_msg_tVT46Wu8tMHAe2jK"}
data: {"type": "finish-step"}
data: {"type": "data-guardrail-violation", "data": {"category": "off_topic_questions", "guardrailType": "input", "fallbackResponse": "I'm sorry I couldn't respond to that, I can only answer questions about Workato's documentation."}}
data: {"type": "finish"}
data: [DONE]
```
The `fallbackResponse` field contains the full intended message; nothing in the compiled library consumes it.
**Suspected root cause**
`grep` of the compiled `@docsearch/sidepanel-js@4.7.0` bundle for `guardrail` or `fallbackResponse` returns zero matches. The library's stream reducer switches on:
`start`, `start-step`, `text-start`, `text-delta`, `text-end`, `finish-step`, `finish`, `tool-call`, `tool-calls`, `tool-input-start`, `tool-input-delta`, `tool-input-available`, `tool-input-error`, `tool-output-available`, `tool-output-error`, `tool-result`, `data-code`
`data-guardrail-violation` is not in that set, so the event has no effect on the message-parts state.
## Expected behavior
The `fallbackResponse` string from the `data-guardrail-violation` event renders as the assistant's message.
**Actual**
Only the first token from the aborted `text-delta` stream renders. On repeated near-duplicate off-topic asks, the delta content shrinks further (single letter → nothing).
[Attach: `Screenshot 2026-07-29 at 2.43.11 PM.png` — shows the empty response bar with just a cursor and the feedback buttons, after asking "what's the capital of sweden"]
## Environment
- OS: macOS
- Browser: Chrome, Chrome Incognito
- `@docsearch/sidepanel-js`: `4.7.0` (reproduced on `4.6.2` as well)
- `@docsearch/css`: `4.7.0`
- Panel variant: `inline`
- `agentStudio: true`
- Guardrail: `off_topic_questions`, `guardrailType: input`
**Contrast case**
docs.algolia.com uses the same library version (`@docsearch/sidepanel-js@4`, currently resolving to `4.7.0`) and does not exhibit this bug — because its assistant does not have any input guardrails enabled, so `data-guardrail-violation` events are never emitted. Off-topic behavior there is handled by the model via its system prompt, producing normal `text-delta` chunks that the library renders correctly.
[Attach: `Screenshot 2026-07-29 at 3.15.53 PM.png` — EventStream from docs.algolia.com showing only `start`/`start-step`/`tool-input-*` events, no `data-guardrail-violation`]
**Suggested fix**
In the stream reducer, add a case for `data-guardrail-violation`: append a new message part rendering `data.fallbackResponse` as the assistant's text, replacing (or appending after) the truncated `text-*` sequence. Any consumer of an Agent Studio input guardrail is currently unusable without this.
Contributor guide
Research direction
Start in the @docsearch/sidepanel-js stream reducer, reviewing its handling of the listed event types and reproducing the provided EventStream. Add handling for data-guardrail-violation so its data.fallbackResponse renders as the assistant message instead of the truncated text-delta output; done means the full fallback string appears for an input guardrail response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100