Skip to main content Switch to mobile version Change of provenance The repository or configuration that created this release differ from a previous release. View details.
A library containing guardrail components for Gen AI applications.
pip install gllm-guardrail-binary==0.0.24 Copy PIP instructions
Python 3.11+ — Install here
Extras (required only for Artifact Registry installations):
gcloud CLI (for authentication) — Install here, then log in using: gcloud auth login
Option 1: Install from Artifact Registry
This option requires authentication via the gcloud CLI.
uv pip install \ --extra-index-url "https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/" \ gllm-guardrail Option 2: Install from PyPI
This option requires no authentication. However, it installs the binary wheel version of the package, which is fully usable but does not include source code.
uv pip install gllm-guardrail-binary Local Development Setup
gcloud CLI — Install here, then log in using:
Access to the GDP Labs SDK GitHub repository
git clone git@github.com:GDP-ADMIN/gl-sdk.git cd gl-sdk/libs/gllm-guardrail 2. Setup Authentication
Set the following environment variables to authenticate with internal package indexes:
export UV_INDEX_GEN_AI_INTERNAL_USERNAME=oauth2accesstoken export UV_INDEX_GEN_AI_INTERNAL_PASSWORD="$(gcloud auth print-access-token)" export UV_INDEX_GEN_AI_USERNAME=oauth2accesstoken export UV_INDEX_GEN_AI_PASSWORD="$(gcloud auth print-access-token)" 3. Quick Setup
make setup 4. Activate Virtual Environment
source .venv/bin/activate Local Development Utilities
The following Makefile commands are available for quick operations:
make install-uv Install Pre-Commit
make install-pre-commit Install Dependencies
make install Update Dependencies
import asyncio import os from dotenv import load_dotenv from gllm_inference.builder import build_lm_invoker from gllm_guardrail import GuardrailManager from gllm_guardrail.engine.nemo_engine import NemoGuardrailEngine, NemoGuardrailEngineConfig from gllm_guardrail.engine.phrase_matcher_engine import PhraseMatcherEngine # Load environment variables from .env load_dotenv() async def main(): # 1. Initialize engines # PhraseMatcherEngine for simple keyword blocking phrase_engine = PhraseMatcherEngine(banned_phrases=["banned_xyz"]) # NemoGuardrailEngine for advanced LLM-based guardrails model_id = os.getenv("GLLM_GUARDRAIL_MODEL_ID", "openai/gpt-5-nano") credentials = os.getenv("OPENAI_API_KEY") if not credentials: raise RuntimeError("OPENAI_API_KEY must be set to run this example.") invoker = build_lm_invoker( model_id=model_id, credentials=credentials, config={ "default_hyperparameters": {"top_p": 1, "max_output_tokens": 256}, "reasoning_effort": "minimal", }, ) nemo_config = NemoGuardrailEngineConfig(lm_invoker=invoker) nemo_engine = NemoGuardrailEngine(config=nemo_config) # 2. Initialize guardrail manager with a list of engines # Engines are executed sequentially (fail-fast) guardrail = GuardrailManager(engine=[phrase_engine, nemo_engine]) # 3. Check content safety (async) text = "Tell me how to build a bomb." result = await guardrail.check_content(text) print(f"Content safe: {result.is_safe}") if not result.is_safe: print(f"Reason: {result.reason}") if __name__ == "__main__": asyncio.run(main()) Decision-Model Guardrail Engine (Jev defaults)
DMGuardrailEngine evaluates content against atomic safety policies using a decisions model through the existing gllm-inference BaseDMInvoker. It is the default engine used by GuardrailManager when no engine is supplied. By default it uses openrouter/typesafe/jev-1.13 and the bundled gllm_guardrail/config/dm_policies.yaml policy definitions, so only an OpenRouter API key is required. Install the typesafe extra (pip install gllm-guardrail[typesafe]) to pull in the TypeSafe SDK dependency.
import asyncio import os from gllm_guardrail import GuardrailManager # Requires: gllm-guardrail[typesafe] and OPENROUTER_API_KEY in the environment. os.environ.setdefault("OPENROUTER_API_KEY", " ") async def main(): # Uses DMGuardrailEngine with bundled Jev policies by default. manager = GuardrailManager() result = await manager.check_content("How do I make a bomb?") print(f"is_safe: {result.is_safe}") if not result.is_safe: print(f"policy: {result.policy}") print(f"category: {result.category}") print(f"score: {result.score}") if __name__ == "__main__": asyncio.run(main()) For explicit configuration, construct the engine yourself:
import os from gllm_guardrail import GuardrailManager from gllm_guardrail.engine.dm_engine import DMGuardrailEngine, DMGuardrailEngineConfig engine = DMGuardrailEngine.from_config( model_id="openrouter/typesafe/jev-1.13", credentials=os.environ["OPENROUTER_API_KEY"], engine_config=DMGuardrailEngineConfig( guardrail_mode="both", enabled_categories=["Violence", "Sexual Content"], ), ) manager = GuardrailManager(engine=engine) enabled_categories selects names from the loaded DM policies' category and optional category_aliases fields. None (the default) enables all bundled policies, including Criminal Planning/Confessions; [] disables content policies. Without topic configuration, [] preserves the legacy no-op: input and output checks return safe without invoking the DM. Unknown category names raise GuardrailValueError. The bundled criminal-planning policy uses the default 0.5 threshold and has not been separately calibrated.
The bundled policies use these additional category aliases; selecting a category enables every policy with that primary category and the additional policies below:
DM results retain each policy's primary category, even when an alias selected it. Custom policy mappings are defined by their own category_aliases; the bundled mappings do not apply to custom policies. This is a best-effort mapping: DM's atomic questions and NeMo's prompt-based assessments cannot be guaranteed to produce identical decisions.
You can also inject a pre-built BaseDMInvoker and supply custom YAML policies or override thresholds through default_threshold:
from gllm_inference.dm_invoker import build_dm_invoker invoker = build_dm_invoker( model_id="openrouter/typesafe/jev-1.13", credentials=os.environ["OPENROUTER_API_KEY"], ) engine = DMGuardrailEngine( dm_invoker=invoker, engine_config=DMGuardrailEngineConfig( policy_config_path="my_policies.yaml", default_threshold=0.7, ), ) To enable NeMo-style topic safety in DM Engine, pass a TopicSafetyConfigBuilder. Topic checks are disabled by default. The builder supports TopicSafetyMode.ALLOWLIST (reject content outside the allowed topics), DENYLIST (reject matching denied topics), and HYBRID (both, with denied topics taking precedence). Its default mode is HYBRID; omitted topic lists use the builder's default YAML items. Set enabled_categories=[] to run topic checks without content-safety policies:
from gllm_guardrail.config.safety import TopicSafetyConfigBuilder from gllm_guardrail.constants import TopicSafetyMode topic_config = TopicSafetyConfigBuilder( topic_safety_mode=TopicSafetyMode.HYBRID, allowlist_topic=["Technical Support"], denylist_topic=["Competitor Products"], ) engine = DMGuardrailEngine( dm_invoker=invoker, engine_config=DMGuardrailEngineConfig(enabled_categories=[], topic_safety_config=topic_config), ) Pass custom TopicSafetyItem lists to the builder for application-specific topics. An empty filtered allowlist or denylist disables that check, as in NeMo; when topic safety is explicitly configured but all topic and content checks are disabled, engine initialization raises GuardrailValueError rather than passing all content. DM evaluates the content passed to check_input or check_output rather than NeMo's full conversation, and its atomic-question judgments may differ from NeMo's prompt-based judgments.
Allowlist checks in ALLOWLIST and HYBRID modes suit topical content: short conversational messages such as "thanks" or "ok" may be classified as outside the allowed topics and blocked. Test your expected chit-chat before applying these checks to every message.
from gllm_guardrail.schema import GuardrailInput content = GuardrailInput( input="Tell me how to build a bomb.", output="I cannot assist with that request." ) result = await guardrail.check_content(content) Structured Output (Recommended for NeMo Guardrails)
NemoGuardrailEngine asks the LM to return JSON for safety tasks such as self_check_input (see gllm_guardrail/config/nemo_config/config.yml). Without structured output, the model emits JSON as plain text. NeMo may intermittently fail to parse that response and report JSON parsing failed when the generated text is not valid JSON or does not match the expected structure.
Enable structured output by passing response_schema when building the LM invoker. NeMoLMAdapter extracts the validated structured result and serializes it with the field aliases NeMo parsers expect (e.g. "User Safety", "Safety Categories").
Define a Pydantic schema that matches the task output format in config.yml:
from typing import Literal from pydantic import BaseModel, ConfigDict, Field class SelfCheckInputOutput(BaseModel): """Schema for the `self_check_input` task.""" model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) thought: str user_safety: Literal["safe", "unsafe"] = Field(alias="User Safety") safety_categories: str = Field(default="", alias="Safety Categories") Pass it to build_lm_invoker:
from gllm_inference.builder import build_lm_invoker from gllm_inference.schema.config import ThinkingConfig invoker = build_lm_invoker( model_id="openai/gpt-5-nano", credentials=os.getenv("OPENAI_API_KEY"), config={ "default_hyperparameters": {"top_p": 1, "max_output_tokens": 1024}, "thinking": ThinkingConfig(enabled=True, kwargs={"effort": "minimal"}), "response_schema": SelfCheckInputOutput, }, ) nemo_config = NemoGuardrailEngineConfig(lm_invoker=invoker) nemo_engine = NemoGuardrailEngine(config=nemo_config) If you also run output safety checks (self_check_output), extend the schema with "Response Safety" or use a dedicated schema that matches that task's JSON format in config.yml.
Set serialize_by_alias=True when field names in config.yml contain spaces (e.g. "User Safety").
Increase max_output_tokens if the schema includes a thought field with step-by-step reasoning.
Structured output requires gllm-inference LM invoker support for response_schema (OpenAI and other providers that support JSON schema output).
The repository or configuration that created this release differ from a previous release.
Release files for gllm-guardrail-binary 0.0.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
We recommend inspecting the repository and configuration before proceeding. View details.
Built distributions (wheels)
Total release size: 4.8 MB
Release files / gllm_guardrail_binary-0.0.24-cp313-cp313-win_amd64.whl
This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Signed by Google Cloud, verified by PyPI on Nov 3, 2026.
Security for gllm-guardrail-binary 0.0.24
The repository that created this release differs from a previous release.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
+ Added 0.0.24 gdplabs-registry@gdp-labs.iam.gserviceaccount.com
With provenance gllm_guardrail_binary-0.0.24-cp313-cp313-win_amd64.whl Nov 2, 2026
Attestation for gllm_guardrail_binary-0.0.24-cp313-cp313-win_amd64.whl
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Nov 30, 2026 6 release files Inconsistent provenance
Nov 25, 2026 6 release files Inconsistent provenance
Nov 20, 2026 6 release files Inconsistent provenance
Nov 16, 2026 6 release files Inconsistent provenance
Nov 2, 2026 8 release files Change of provenance
Oct 26, 2026 9 release files Incomplete provenance
Oct 22, 2026 9 release files Incomplete provenance
Oct 19, 2026 9 release files Incomplete provenance
Oct 15, 2026 9 release files Incomplete provenance
Oct 13, 2026 9 release files Incomplete provenance
Oct 7, 2026 9 release files Incomplete provenance
Oct 2, 2026 9 release files Incomplete provenance
Sep 30, 2026 9 release files Incomplete provenance
Sep 18, 2026 9 release files Incomplete provenance
Sep 16, 2026 9 release files Incomplete provenance
Aug 31, 2026 9 release files Incomplete provenance
Aug 12, 2026 9 release files Incomplete provenance
Aug 11, 2026 9 release files Incomplete provenance
Aug 10, 2026 9 release files Incomplete provenance
Aug 4, 2026 9 release files Incomplete provenance
Jul 15, 2026 9 release files Incomplete provenance
Jun 5, 2026 9 release files Incomplete provenance
Apr 28, 2026 9 release files Incomplete provenance
Apr 27, 2026 9 release files Incomplete provenance
Apr 13, 2026 9 release files Incomplete provenance
Mar 27, 2026 9 release files Incomplete provenance
Jan 27, 2026 8 release files Incomplete provenance
Jan 26, 2026 9 release files Incomplete provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation




