nemoguardrails.testing.fake_model
nemoguardrails.testing.fake_model
Framework-agnostic fake LLM model for testing guardrails configurations.
This module exposes :class:FakeLLMModel, a lightweight implementation of the
LLMModel protocol used by NeMo Guardrails. It is intended for use in tests
where a deterministic, scripted set of responses is preferable to calling out
to a real model provider.
Module Contents
Classes
API
Framework-agnostic fake LLM for testing. Implements the LLMModel protocol.
Parameters:
A list of plain string responses. Each call to
:meth:generate_async (or :meth:stream_async) consumes the next
entry. Mutually exclusive with llm_responses.
A list of :class:~nemoguardrails.types.LLMResponse
objects. Useful when tool calls or structured fields need to be
asserted. Takes precedence over responses when provided.
An exception instance to raise on every generation, useful for exercising error-handling paths.
Optional list of token usage dictionaries (one per
response). Each entry may include prompt_tokens,
completion_tokens and total_tokens keys.
When True, populate
:attr:LLMResponse.usage from token_usage.