> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/relay/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/relay/_mcp/server.

# Struct Plugin Context

> Borrowed safe wrapper around a host plugin registration context.

Generated from `cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-pii-redaction -p nemo-relay-ffi -p nemo-relay-types -p nemo-relay-plugin -p nemo-relay-worker-proto -p nemo-relay-worker`.

```rust
pub struct PluginContext<'a> { /* private fields */ }
```

Borrowed safe wrapper around a host plugin registration context.

## Implementations

### `impl<'a> PluginContext<'a>`

<pre />

#### `from_raw`

<pre />

Creates a plugin context wrapper from raw ABI parts.

##### Safety

`host` and `raw` must remain valid for the lifetime of this wrapper.

#### `host_api`

<pre />

Returns the host ABI table backing this registration context.

#### `runtime`

<pre />

Returns a cloneable high-level runtime handle.

#### `register_subscriber`

<pre />

Registers a typed event subscriber callback.

#### `register_mark_sanitize_guardrail`

<pre />

Registers a typed mark event sanitizer.

#### `register_scope_sanitize_start_guardrail`

<pre />

Registers a typed scope-start event sanitizer.

#### `register_scope_sanitize_end_guardrail`

<pre />

Registers a typed scope-end event sanitizer.

#### `register_tool_sanitize_request_guardrail`

<pre />

Registers a typed tool sanitize-request guardrail.

#### `register_tool_sanitize_response_guardrail`

<pre />

Registers a typed tool sanitize-response guardrail.

#### `register_tool_conditional_execution_guardrail`

<pre />

Registers a typed tool conditional-execution guardrail.

#### `register_tool_request_intercept`

<pre />

Registers a typed tool request intercept.

#### `register_tool_execution_intercept`

<pre />

Registers a typed tool execution intercept.

The callback returns a [`ToolExecutionInterceptOutcome`](/reference/api/rust-library-reference/nemo-relay-plugin/struct-toolexecutioninterceptoutcome). Calling [`ToolNext::call`](/reference/api/rust-library-reference/nemo-relay-plugin/struct-toolnext) continues the chain and returns only the raw downstream result JSON; Relay retains downstream pending marks.

#### `register_llm_sanitize_request_guardrail`

<pre />

Registers a typed LLM sanitize-request guardrail.

#### `register_llm_sanitize_response_guardrail`

<pre />

Registers a typed LLM sanitize-response guardrail.

#### `register_llm_conditional_execution_guardrail`

<pre />

Registers a typed LLM conditional-execution guardrail.

#### `register_llm_request_intercept`

<pre />

Registers a typed LLM request intercept.

#### `register_llm_execution_intercept`

<pre />

Registers a typed LLM execution intercept.

#### `register_llm_stream_execution_intercept`

<pre />

Registers a typed LLM stream execution intercept.

Native ABI v2 represents stream execution as one JSON result. The host wraps that result as a one-chunk stream.

#### `register_subscriber_raw`

<pre />

Registers a raw event subscriber callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_mark_sanitize_guardrail_raw`

<pre />

Registers a raw mark event sanitizer callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_scope_sanitize_start_guardrail_raw`

<pre />

Registers a raw scope-start event sanitizer callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_scope_sanitize_end_guardrail_raw`

<pre />

Registers a raw scope-end event sanitizer callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_tool_sanitize_request_guardrail_raw`

<pre />

Registers a raw tool sanitize-request guardrail callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_tool_sanitize_response_guardrail_raw`

<pre />

Registers a raw tool sanitize-response guardrail callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_tool_conditional_execution_guardrail_raw`

<pre />

Registers a raw tool conditional-execution guardrail callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_tool_request_intercept_raw`

<pre />

Registers a raw tool request intercept callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_tool_execution_intercept_raw`

<pre />

Registers a raw tool execution intercept callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_llm_sanitize_request_guardrail_raw`

<pre />

Registers a raw LLM sanitize-request guardrail callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_llm_sanitize_response_guardrail_raw`

<pre />

Registers a raw LLM sanitize-response guardrail callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_llm_conditional_execution_guardrail_raw`

<pre />

Registers a raw LLM conditional-execution guardrail callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_llm_request_intercept_raw`

<pre />

Registers a raw LLM request intercept callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_llm_execution_intercept_raw`

<pre />

Registers a raw LLM execution intercept callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_llm_stream_execution_intercept_raw`

<pre />

Registers a raw LLM stream execution intercept callback.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid for every host callback invocation until the host deregisters the callback or calls `free_fn`. `free_fn` must match the allocation behind `user_data`.

#### `register_async_middleware_raw`

<pre />

Registers completion-based asynchronous middleware through the ABI-v3 extension table.

Plugins built against older hosts receive [`NemoRelayStatus::InvalidArg`](/reference/api/rust-library-reference/nemo-relay-plugin/enum-nemorelaystatus) instead of attempting to read beyond the legacy host table.

##### Safety

`cb`, `user_data`, and `free_fn` must remain valid until the host deregisters the callback or invokes `free_fn`. A callback returning `Pending` must settle and release its completion/next references. [`NemoRelayNativeAsyncMiddlewareKind::LlmStreamExecutionIntercept`](/reference/api/rust-library-reference/nemo-relay-plugin/enum-nemorelaynativeasyncmiddlewarekind) is rejected; use [`Self::register_async_stream_middleware_raw`](/reference/api/rust-library-reference/nemo-relay-plugin/struct-plugincontext) instead.

#### `register_async_stream_middleware_raw`

<pre />

Registers an incremental completion-based LLM stream intercept.

##### Safety

The callback and user data must remain valid until deregistration or `free_fn`; callback-owned `next` and `stream` handles must each be released exactly once. Stream pushes and rejection are nonblocking: `Internal` with a host last-error containing `backpressured` means the bounded queue is full and the operation may be retried. The output stream owns the callback lifetime. `next` may be invoked repeatedly or concurrently until that stream settles; Relay then rejects or cancels unfinished and later calls.