Testing WebSocket chat services with garak starts with the streaming session
A chat product that streams its replies over a WebSocket cannot be tested well with a plain REST generator, because a REST call returns only what the endpoint sends back in one response and misses the frames that carry the rest of the answer. garak's WebSocket generator, added in v0.14.1 (3 April 2026), is the supported way to send probes into that session and collect the full reply. Before you plan the scan, confirm with your engineering team which WebSocket URL the browser or mobile client actually opens, and whether the server expects a handshake, a session token or a first message before it accepts prompts.
The generator supports four auth types: none, basic, bearer and custom. It also takes a request template that shapes each outgoing message to match your protocol, JSON response field extraction that pulls the assistant text out of the frames, and a typing indicator setting so that status frames are not mistaken for answers. By default it applies a 20-second request timeout and a 10-second connection timeout, and it reads credentials from the WEBSOCKET_API_KEY environment variable. Check each default against how your product behaves under load, since a slow streaming model can exceed the request timeout and produce failures that reflect your configuration rather than the model. The generator source in the garak repository lists the exact keys and their behavior.
Because the generator drives the same session path your users use, the scan covers the application layer around the model: the connection handshake, the authentication your chat service applies, any message wrapping and the way the client assembles streamed text. A test against the bare model API would miss weaknesses in that layer, such as prompts that succeed only after a session-specific message format is applied. Agree the test account, the session lifetime and the rate limits with the owners of the chat product before the first run, so that the probes do not trigger lockouts or contaminate production conversation history.
What you need before pointing garak at a WebSocket endpoint
Most delays in a WebSocket scan come from setup, not from garak itself. The five items below cover the tool, the account, the endpoint, the network path and the credentials, and each one should be settled before the first probe runs. Work through them in order so that a failed connection can be traced to one cause.
garak installed on a supported host
Install garak from PyPI with pip on Linux or macOS, using Python 3.11 or newer, as the PyPI package requires. Confirm the version includes the WebSocket generator: it arrived in v0.14.1 (3 April 2026), and v0.17.1 is the latest release cited. Pin the version you test with, because scores can shift between releases and comparisons depend on a stable tool.
garak releasesA dedicated test account
Create a test user on the chat product with the same role, permissions and plan that your real users have. Avoid running probes as an administrator, because an admin session can expose tools and data that a normal user never reaches. Ask the product team whether the account can be isolated, reset after a scan and excluded from production analytics and billing.
The WebSocket URL and reachable path
Record the exact ws:// or wss:// endpoint, the path, any query parameters and the port. Confirm that the machine running garak can reach it through your firewalls, egress rules and proxies, and that the connection survives the duration of a long scan. Ask whether the endpoint is a direct service or sits behind an API gateway, load balancer or WAF, since each of these can close idle sockets, rate limit or rewrite messages.
TLS certificates and gateway behavior
Verify that the certificate chain on a wss:// endpoint is trusted by the scanning host, including any internal certificate authority. A failed handshake often looks like a generator error, so check it first with a plain client. Also ask whether a gateway enforces idle timeouts, message size limits or per-connection rate limits, because those settings determine the timeouts you configure and how many attempts a probe can complete.
A credential handling plan
Decide where the test token or password will live before you write any configuration. The generator reads keys from WEBSOCKET_API_KEY, so keep that value in a secrets store or a restricted shell session rather than in a config file committed to version control. Plan a rotation date for the test credential, and record who can read the garak report and log files, since prompts and responses from the chat product may appear in them.
How to configure the garak WebSocket generator step by step
This sequence takes a team from a clean garak install to a verified, low-volume WebSocket scan, with each step confirmed before the next begins so that configuration faults are found early.
Install garak and confirm the Python version
Someone on the testing team installs garak from PyPI with pip into a virtual environment on a Linux or macOS host. The PyPI package requires Python 3.11 or newer, so check the interpreter version before installing. Run the garak help command from the same environment. Done means the command prints its usage text without import errors, and the version you see matches the release your team has agreed to pin.
Set the WebSocket API key environment variable
Export WEBSOCKET_API_KEY in the shell that will run garak, or load it from your secrets store into the job environment. Keep the value out of the config file and out of shell history, and do not commit it to a repository. Done means a non-interactive check, such as printing the variable's length rather than its value, shows it is set in the same session that will launch the scan. Confirm with your application team which credential the endpoint expects for the auth type you choose.
Write the generator config with the endpoint
Create a YAML config file that names the WebSocket endpoint URL and the auth type, which is none, basic, bearer or custom. Your platform team should confirm the exact URL scheme and whether the chat service expects a path or query parameter for the session. Use a placeholder endpoint in shared copies of the file. Done means the file parses as valid YAML and contains no secret values.
Define the request template and JSON response field
Add the request template that matches the message format your chat service accepts, with a placeholder where garak inserts the prompt. Then name the JSON field that holds the model's reply, for example the key that carries the message text in a streamed response. Confirm the field path by capturing one real exchange from a browser developer tools session or a test client against a non-production account. Done means a manual test message returns a JSON payload in which you can locate the reply field.
Check timeouts and typing indicator handling
Review the defaults for the request timeout and connection timeout in the generator source before changing them, and decide whether your service sends typing indicator frames that should be skipped. Record the values you chose in the config so later runs match. If your service is slower than the defaults, raise the timeouts deliberately and note why. Done means the config states each timeout and typing indicator setting explicitly, and a single manual exchange completes within those limits.
Run one low-volume probe
Start with a single probe and a reduced number of generations so the first run stays small and cheap to repeat. Invoke garak with your config file and the probe name, and watch the console for connection errors, authentication failures and timeouts. Done means the run finishes without transport errors and garak reports attempts against the WebSocket target rather than an unrelated generator.
Verify the JSONL report and garak.log
Open the JSONL report written by the run and confirm that each attempt contains a non-empty response extracted from your configured JSON field, not raw frame data or an empty string. Then read garak.log for warnings about field extraction, typing indicators or timeouts. Done means every sampled attempt holds extracted reply text and the log shows no unresolved errors. If responses are empty, return to the response field path before running more probes.
Choosing basic, bearer or custom authentication
The none type suits a chat service that accepts WebSocket connections without credentials, usually a staging build or an internal demo bound to a private network. The client team needs only the WebSocket URL and confirmation that the endpoint really is open to the scanning host. Because no secret is involved, there is nothing to store, but that also means the scan exercises the product without the access controls real users face.
- Identity model: anonymous or network-restricted access, with no per-user identity in the handshake.
- Client team needs: the endpoint URL and network path from the scanning host.
- Secret storage: none required by the generator.
- Coverage gap: authentication, session and rate-limit behavior after login is not exercised.
- Before you use it: confirm that no production user data or personal sessions are reachable through the endpoint.
If the production product requires login, a scan with none tests a different surface than your customers reach, so plan a separate run with credentials.
The basic type sends a username and password, the pattern used when a chat service sits behind HTTP-style basic authentication or accepts a shared account for machine access. The client team must provision a dedicated test account with the narrowest role that still reaches the chat features under test, and must agree who owns its rotation. Basic credentials are long-lived by nature, so the account should be easy to disable once testing ends.
- Identity model: a static account, often a service or test user rather than a named person.
- Client team needs: a provisioned test account, its permitted features and a rotation owner.
- Secret storage: supplied through environment variables for the scan process, never written into the generator configuration file.
- Logging risk: credentials can appear in logs or shell history, so review the garak.log and command invocation before sharing output.
- Exit step: disable the account when the engagement closes.
Confirm with the product owner that the account's permissions match the chat paths in scope, because a broader account changes what the findings represent.
The bearer type sends a token, typically one issued by an identity provider or by the chat product's own login flow, so it fits products where users sign in with single sign-on and the application issues tokens. The client team must decide how the token is obtained for a scan, since tokens expire and a manually copied token will fail partway through a long run. A dedicated service identity that issues tokens with a known lifetime is usually easier to manage than a personal user token.
- Identity model: token-based sessions tied to a user or service principal.
- Client team needs: a token source, its expiry behavior and a refresh approach.
- Secret storage: the token is read from the environment, so it should come from your secrets manager at run time.
- Expiry risk: a token that lapses mid-scan produces failures that look like product defects, so record the lifetime before the run.
- Avoid: personal session tokens that carry an individual's permissions.
Confirm the token lifetime and whether the product's WebSocket handshake accepts the token in the header form the generator sends.
The custom type exists for handshake patterns the built-in types do not cover, such as a token exchanged in a first message, a signed connection request or a vendor-specific header scheme. It gives flexibility, but it moves responsibility for correctness onto the team configuring it. Before choosing custom, confirm in the generator source how it builds and sends the handshake and what it expects in return, because the behavior is what matters rather than the name of the option.
- Identity model: whatever the product defines, often a multi-step exchange or a signed request.
- Client team needs: a precise description of the handshake from the product's engineers, with example traffic from a test environment.
- Secret storage: keys and signing material belong in a secrets manager, supplied at run time.
- Verification: run a single probe against a test account first and inspect the traffic and the JSON response fields.
- Ownership: the configuration must be reviewed whenever the chat product changes its handshake.
Where the source does not show the behavior you need, treat the configuration as unverified and ask the product team or the garak maintainers before relying on its results.
How request templates and JSON response fields shape the scan
The request template has to match the message format your chat product actually expects, because garak sends whatever the template produces and the service either answers it or silently ignores it. A template built from the vendor's marketing docs or from memory often differs in key names, nesting, event types or required session identifiers. Before writing the template, capture one real session with your browser's developer tools (the WebSocket frames view in the network panel) or with a WebSocket client pointed at the same endpoint. Record the exact JSON sent when a user submits a message, including any conversation or session ID, and the frames the server returns. Confirm with the product team which fields are mandatory and which are optional, and whether the server expects a handshake message before the first prompt.
The JSON response field setting must point at the frame and field that carry the assistant's text, and nothing else. Chat services commonly stream several frame types over the same socket, such as typing indicators, acknowledgements, heartbeats, delivery receipts, token deltas and a final completion event. If the extraction path lands on a status frame or a metadata field, garak scores empty or unrelated text, and a probe can report a pass that never tested the model. Compare the captured frames against your extraction path for each event type, and decide whether the scan should read partial token deltas, the final message, or both. Run a short test with a single known prompt and check the stored attempt in the JSONL report before scaling up. Illustrative example: if the answer appears in a delta field on many frames and in a message field on the last frame, the path you configure determines which of those the detectors see.
How a garak probe travels through a WebSocket session
The flow starts at the garak harness on the scanning host, which hands each prompt to the WebSocket generator. The generator performs the configured authentication, fills the request template and sends the message over the socket to the chat service inside its own network. The reply comes back as a stream, and the generator extracts the configured JSON field before the detectors evaluate the text. Check that the scanning host can reach the chat service and that the extracted field holds the reply text, not metadata.
One prompt's path from the garak harness through the trust boundary and back to detection.
Mapping garak settings to the chat product's session fields
This table pairs each garak WebSocket generator setting with the matching field in the chat product, names who supplies the value, and says where to confirm it. Read it before the first connection test, because a mismatch in any row usually shows up as a failed handshake or an empty reply rather than a clear error.
| Setting | Chat product equivalent | Who supplies it and where to confirm |
|---|---|---|
| Endpoint (WebSocket URL) | The socket address the chat client opens for a session | Product or platform team; confirm in the client's network traffic or the service configuration |
| Auth type (none, basic, bearer, custom) | How the chat service authenticates the socket handshake | Security or identity team; confirm against the product's auth documentation and a manual connection |
| API key variable (WEBSOCKET_API_KEY) | The token or password issued for the test account | Test account owner; store it in the scan host's environment, never in the config file |
| Request template placeholder | The message frame shape the client sends for one user turn | Product engineers; copy a real outgoing frame from a browser session and replace the user text with the placeholder |
| JSON response field | The frame field that carries the assistant's text | Product engineers; read a sample streamed response and identify the field that holds the final text, not the partial tokens |
| Typing indicator | The status frame the service sends while it is generating | Product engineers; confirm whether the service sends one, and what it looks like, before enabling it |
| Request timeout (20 seconds by default) | Longest wait for a complete reply after a message is sent | Platform team; compare with the slowest normal reply under load and raise it if replies routinely take longer |
| Connection timeout (10 seconds by default) | Longest wait to establish the socket and complete the handshake | Network team; confirm proxy, load balancer and idle-timeout settings between the scan host and the service |
Security controls for scanning a live chat service
A WebSocket scan sends adversarial prompts into a service your users depend on, and the results hold sensitive material. The controls below cover credentials, the identity garak uses, where scans originate, how output is stored, and when testing is allowed to run.
Keep the API key out of files and history
The WebSocket generator reads its key from the WEBSOCKET_API_KEY environment variable, so the key does not need to appear in a generator config file. Set it in the scan host's secret store or a session that loads it at run time, and keep it out of shell history by avoiding inline export commands typed at a prompt. Check that config files, CI logs and shared notebooks contain no copy of the key. Rotate it after any scan that ran from a shared machine.
Use a dedicated scan account
Create a separate account on the chat service for garak, not a personal or administrator login. Give it the same role an ordinary end user has, since that is the exposure an attacker would have, and confirm it cannot reach admin APIs, other tenants or stored customer conversations. Ask the service owner whether the account's messages are visible to staff or used for model training, and label its conversations so they can be filtered out of analytics.
Restrict the scan host by network
Run garak from a host with a fixed, known address and allow outbound WebSocket connections only to the chat service's endpoint. Block other egress so a misconfigured probe or a compromised dependency cannot reach unrelated systems. If the service sits behind an allowlist or a web application firewall, agree the source address with the owner before the first run so the scan is not mistaken for an attack.
Protect reports and logs
Each run writes a JSONL report of every attempt and a garak.log file that continues across runs. Both contain the probe prompts and the model's replies, which may include leaked data or unsafe content. Store them in an access-controlled location with a named owner, limit read access to the security team, and set a retention period agreed with compliance. Do not paste excerpts into tickets or chat channels without review.
Agree rate limits and scan windows
Ask the service owner for a request rate the platform can absorb, a maximum number of concurrent connections, and the hours when scanning is permitted. garak makes several generations per prompt by default, so a probe set multiplies traffic quickly. Confirm the 20-second request and 10-second connection timeouts suit the service, and stop the run if error rates or latency rise on production users.
Record the authorization in writing
Before scanning, keep a written statement from the service owner that names the endpoint, the scan account, the source hosts, the permitted window and the contact for stopping a run. This record shows the test was authorized and defines who decides whether a finding is escalated. Keep it with the reports so the evidence trail is complete.
Why WebSocket scans fail and how to fix them
This table lists the failures teams most often hit when pointing garak's WebSocket generator at a streaming chat service, with the likely cause and the fix for each. Check the connection and request timeouts first, then the auth settings, then the response field and typing indicator handling, because those account for most empty or misleading results.
| Failure | Likely cause | Fix |
|---|---|---|
| Connection timeout | The socket does not open within the 10-second default connection timeout, often due to TLS setup, a load balancer, or a cold start on the chat service | Confirm the WebSocket URL and scheme, test the handshake from the scan host, and raise the connection timeout in the generator config if the service is slow to accept connections |
| Request timeout on slow replies | The model takes longer than the 20-second default request timeout to finish streaming, common with large models or long system prompts | Raise the request timeout for the scan, then confirm the chat service's own idle and response limits allow longer waits |
| Authentication rejected (basic or bearer) | The auth type does not match what the service expects, or the key in WEBSOCKET_API_KEY is missing, expired or sent in the wrong format | Match the auth type to the service's documented handshake, check the key value and its scope, and try the custom auth type if the service needs a header or token format basic or bearer cannot produce |
| Empty responses | The JSON response field setting points at the wrong key, so garak reads nothing from the frames the service sends | Capture one raw frame from the service, identify the field that holds the reply text, and set the response field extraction to that path |
| Typing indicator counted as an answer | Status frames such as typing or progress events arrive before the reply and are read as model output, which can hide or distort failures | Enable the typing indicator handling so status frames are skipped, then review a few JSONL entries to confirm each attempt holds a real reply |
| Session expiry mid-run | The chat service closes long-lived sockets or invalidates tokens partway through a scan with many attempts | Split the run into smaller batches, confirm how long a session lasts with the service owner, and check garak.log for repeated connection errors after a set number of attempts |
| Request template mismatch | The request template does not match the message format the chat service expects, so prompts are rejected or ignored | Send a manual test message with the same structure, compare it with the template, and fix field names and nesting before starting a full scan |
Questions buyers ask before testing a WebSocket chat service
What drives the effort of a WebSocket chat scan with garak?
The effort depends mostly on how much of the chat protocol you must reproduce before a prompt can be sent and a reply read. garak's WebSocket generator needs a request template that matches the message format the product expects, a rule for pulling the reply text out of each JSON response, and handling for typing indicators and other non-answer frames. Session complexity matters most: a product that needs a login handshake, a conversation ID, or several frames per turn takes more setup than one that accepts a single message and returns a single reply. Scan size also matters, because garak makes 5 generations per prompt by default and each probe multiplies the number of requests. Ask the chat vendor for its message format and authentication flow before you estimate anything.
Can our team run a WebSocket scan without outside help?
Yes, if you have an engineer who can read a WebSocket protocol, write a YAML configuration and debug a JSON response mapping. garak is a free command-line tool installed from PyPI, and the PyPI package requires Python 3.11 or newer. The WebSocket generator was added in garak v0.14.1 (3 April 2026), so confirm that your installed version includes it. Your team will need to decide which probes to run, how to interpret the JSONL report and how to repeat the run after changes. Teams without spare engineering time, or without anyone who has tested conversational systems before, often bring in a partner for the first scan and keep the configuration for their own reruns.
What does the work need from our engineers and product owners?
Engineers need access to a test environment that behaves like production, credentials for a dedicated test account, and the WebSocket endpoint details. Product owners need to confirm which conversation flows matter, which topics the assistant must refuse, and which data the chat can reach. In practice this means:
- A staging endpoint or test tenant with realistic but non-customer data
- Documented message formats, handshake steps and reply structure
- A named owner who can approve probe selection and review findings
Without these, the scan can only test the happy path, which tells you little about the weaknesses that matter.
How long does a first WebSocket scan take?
The duration depends on session complexity and the size of the probe set, not on a fixed number. A chat that accepts one message and returns one reply can be configured and run quickly, while a product with authentication refresh, multi-frame replies or conversation state needs more configuration and more checks on the output. Run time also depends on the endpoint's response speed, the 20-second request timeout and 10-second connection timeout that the generator uses by default, and any rate limits the vendor applies. The garak documentation at docs.garak.ai describes these settings. Ask for a written scope that lists the flows, probes and retest rounds before agreeing on a timeline.
Is garak free to use under the Apache 2.0 license?
garak is licensed under Apache 2.0, and the maintainers describe it as a free tool. The license lets you run, modify and use it inside your organization, subject to the license terms, so the software itself does not carry a license fee. Your costs come from the people who configure and run scans, the compute and API usage of the models you test, and any outside engagement. Confirm the license text and any third-party terms for the model providers your chat product uses with your legal team, because those terms govern the model calls rather than garak.
What does a DeployOpen engagement cover for WebSocket chat testing?
DeployOpen runs security testing of AI systems and agents, and that includes setting up garak against a chat product in a scoped engagement. Typical work includes agreeing the scope in writing, configuring the WebSocket generator for the product's authentication and message format, running the agreed probes, reviewing the findings with your team and retesting after fixes. Engagements are fixed-scope, so deliverables and timelines are agreed before work starts, and a quote follows from that written scope. DeployOpen does not issue audit reports or certifications. Ongoing testing after launch can be handled through a retainer.
What should we confirm with the chat vendor before testing?
Confirm the testing rules and the technical details before any probe is sent. Ask whether the vendor permits adversarial testing on a staging or dedicated tenant, what rate limits apply, and whether test traffic is logged or billed. Get the WebSocket endpoint, the authentication type (none, basic, bearer or a custom scheme), the message schema, the field that carries the reply text and how the product signals typing or completion. Also confirm which upstream model providers sit behind the chat, since their terms and quotas apply to every probe. Put these answers in writing so the configuration and the scan record match what the vendor agreed to.
How DeployOpen scopes and runs garak scans against chat services
DeployOpen plans and runs garak scans against WebSocket chat services inside the client's own infrastructure, starting from a written scope. The work covers the connection settings, authentication, message templates and response parsing that the WebSocket generator needs, followed by documented scan runs and a handover the client's own team can repeat.
How we scope
- Engagements are fixed-scope, with the chat endpoints, auth types and probe families agreed in writing before work starts.
- We confirm which environments may be tested, including staging versus production, and who owns the test accounts.
- The scope names the WebSocket message format, typing indicator behavior and the JSON fields that carry the reply text.
How we build
- We configure the garak WebSocket generator with the agreed auth type, request template and response field extraction.
- We set the request and connection timeouts against the chat service's actual latency and document any changes from defaults.
- We keep API keys in environment variables such as WEBSOCKET_API_KEY and check that no secret appears in config files or reports.
How we hand over
- You receive the generator configuration, probe selection and run commands in version-controlled files.
- Scan results include the JSONL report and garak.log with a written explanation of failed probes and reproduction steps.
- We document how to rerun scans after a garak upgrade and how to confirm a connection failure is an endpoint problem, not a scan result.
How we support
- Ongoing support, garak upgrades and scheduled rescans are available as a retainer under the same written scope.
- Retesting after fixes is included in the scope when agreed, so you can confirm that remediated probes now pass.
- Ask us to confirm the WebSocket generator behavior for your garak version before a scan cycle begins.

