Skip to content

Adapter

Adapter for guardrail components.

NeMoLMAdapter(model=None, lm_invoker=None, fallback_lms=None, **kwargs)

NeMo LLMModel protocol adapter that delegates to a gllm_inference LM invoker.

Pass lm_invoker to supply the primary invoker; the model identifier is derived from it automatically via lm_invoker.model_id. The model parameter is optional and exists so NeMo's framework can set it when the adapter is registered as a provider — you do not need to pass it directly.

Attributes:

Name Type Description
model str | None

Model identifier string.

lm_invoker BaseLMInvoker | None

Primary LM invoker.

fallback_lms list[BaseLMInvoker]

Ordered fallback invokers tried on BaseInvokerError or TimeoutError from the primary.

model_name str

Identifier used by NeMo for logging and serialization.

provider_name str | None

Provider name registered with NeMo Guardrails.

provider_url str | None

Provider URL; not applicable for this adapter.

Initializes a new instance of the NeMoLMAdapter class.

Parameters:

Name Type Description Default
model str | None

Model identifier string. Defaults to None.

None
lm_invoker BaseLMInvoker | None

Primary LM invoker. Defaults to None.

None
fallback_lms list[BaseLMInvoker] | None

Ordered fallback invokers tried on BaseInvokerError or TimeoutError from the primary. Defaults to None.

None
**kwargs Any

Additional keyword arguments forwarded from the NeMo framework.

{}

model_name property

Identifier used by NeMo for logging and serialization.

provider_name property

Provider name registered with NeMo Guardrails.

provider_url property

Provider URL; not applicable for this adapter.

generate_async(prompt, *, stop=None, **kwargs) async

Asynchronously generate a response via the invoker.

Tries the primary invoker first. On BaseInvokerError or TimeoutError, falls back to each invoker in fallback_lms in order until one succeeds or the list is exhausted, then re-raises the last exception.

Parameters:

Name Type Description Default
prompt str | list[ChatMessage]

Input prompt as a string or list of NeMo chat messages.

required
stop list[str] | None

Stop sequences. Defaults to None.

None
**kwargs Any

Optional runtime parameters forwarded to the invoker.

{}

Returns:

Name Type Description
LLMResponse LLMResponse

The generated response from the first successful invoker.

Raises:

Type Description
BaseInvokerError

Re-raised from the last fallback invoker if all fail.

TimeoutError

Re-raised from the last fallback invoker if all fail.

stream_async(prompt, *, stop=None, **kwargs) async

Stream a response, yielding text deltas as they are generated.

Runs the invocation in the background while forwarding text deltas emitted by the invoker's event emitter as they arrive. A final chunk carrying the finish reason and token usage is yielded once the invocation completes. Note that the finish reason is always "stop", since LMOutput does not expose the underlying provider's finish reason.

Parameters:

Name Type Description Default
prompt str | list[ChatMessage]

Input prompt as a string or list of NeMo chat messages.

required
stop list[str] | None

Stop sequences. Defaults to None.

None
**kwargs Any

Optional runtime parameters forwarded to the invoker.

{}

Yields:

Name Type Description
LLMResponseChunk AsyncIterator[LLMResponseChunk]

Incremental chunks of the response as they are generated, followed by a final chunk carrying the finish reason and token usage.