nemoguardrails.llm
Subpackages
Submodules
nemoguardrails.llm.callnemoguardrails.llm.completion_parsingnemoguardrails.llm.constantsnemoguardrails.llm.filtersnemoguardrails.llm.openai_reasoningnemoguardrails.llm.output_parsersnemoguardrails.llm.promptsnemoguardrails.llm.providersnemoguardrails.llm.taskmanagernemoguardrails.llm.telemetrynemoguardrails.llm.types
Package Contents
Classes
Functions
Data
API
Create a ChatMessage from a dict.
Accepts both the canonical nested tool call format
({"function": {"name": ..., "arguments": ...}}) and the legacy
flat format ({"name": ..., "args": ...}). JSON string arguments
are parsed automatically. Role aliases like “bot”, “human”, and
“developer” are mapped to canonical Role values. Unknown keys are
captured into provider_metadata.
Protocol for pluggable LLM framework backends.
Each framework (LangChain, LiteLLM, etc.) implements this protocol to
provide a factory for creating LLMModel instances and managing
its own set of providers.
model_kwargs carries all provider-specific configuration. Framework
implementations extract what they need (e.g. LangChain pops mode
to choose between chat and text completion models).
Release all framework-owned resources and clear all registered state.
Implementations should close any pooled connections, clear registered providers, and return the framework to its initial state. Callers can continue using the instance after reset; new resources will be created on demand.
Protocol that all LLM backends must implement.
Adapters wrap provider-specific SDKs (LangChain, LiteLLM, OpenAI, etc.) behind this interface so the core pipeline remains framework-agnostic.
prompt accepts either a plain string or a list of ChatMessage
objects. Adapters convert ChatMessage to whatever their SDK expects.
**kwargs are forwarded to the underlying SDK (e.g. temperature,
max_tokens).
Implementations must be async generator functions (use yield).
Bases: enum.Enum
Register an LLMFramework instance under name.
Validates two invariants before storing the instance:
- The object structurally matches the
LLMFrameworkProtocol (create_model,register_provider,get_provider_names,reset). - Its
resetattribute is anasynccoroutine function. The registry awaits it directly during shutdown / test teardown.
Raises:
ValueError: a framework is already registered undername.TypeError:frameworkdoes not implement theLLMFrameworkProtocol, or itsresetis not an async coroutine function.