Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

WebSocket Target

WebsocketTarget connects PyRIT to services that use a custom WebSocket protocol. Supply the service-specific initialization messages, prompt builder, and response parser. The protocol_identifier is a non-secret name for this complete protocol configuration.

This example starts a local PyRIT WebSocket service. It exercises the real WebSocket transport without credentials or an external endpoint.

Start the local service on an available loopback port, then configure the target for its protocol.

The restore callback is service-specific. PyRIT calls it when a multi-turn conversation needs a replacement connection. Without this callback, the target fails instead of silently losing history.

Send a prompt through the target and close both sides of the connection.

Cleanup is terminal for this target instance. If a connection fails while a prompt is in progress, the target discards that connection and raises the error instead of retrying the prompt.

PyRIT received: Hello