A library containing guardrail components for Gen AI applications.
Project description
GLLM Guardrail
Description
A library containing guardrail components for Gen AI applications.
Installation
Prerequisites
Mandatory:
- Python 3.11+ — Install here
- pip — Install here
- uv — 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
Prerequisites
-
Python 3.11+ — Install here
-
pip — Install here
-
uv — Install here
-
gcloud CLI — Install here, then log in using:
gcloud auth login
-
Git — Install here
-
Access to the GDP Labs SDK GitHub repository
1. Clone 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
Run:
make setup
4. Activate Virtual Environment
source .venv/bin/activate
Local Development Utilities
The following Makefile commands are available for quick operations:
Install uv
make install-uv
Install Pre-Commit
make install-pre-commit
Install Dependencies
make install
Update Dependencies
make update
Run Tests
make test
Usage
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())
Input & Output Checking
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gllm_guardrail_binary-0.0.5-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 336.8 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ead3ba78daaacf14ade5bcc46b31fe39aea366bbf88e73935b151636060d5447
|
|
| MD5 |
2eca8d7047608854b34ff754cbb42628
|
|
| BLAKE2b-256 |
e7a2a1c6e99521dcfd216b670b690324c61221ba5508e2d8389c9960ea11cdad
|
Provenance
The following attestation bundles were made for gllm_guardrail_binary-0.0.5-cp313-cp313-win_amd64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_guardrail_binary-0.0.5-cp313-cp313-win_amd64.whl -
Subject digest:
ead3ba78daaacf14ade5bcc46b31fe39aea366bbf88e73935b151636060d5447 - Sigstore transparency entry: 855052442
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@da37679695af4ae02d3197d76f23499d2256abef -
Branch / Tag:
refs/tags/gllm_guardrail-v0.0.5 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@da37679695af4ae02d3197d76f23499d2256abef -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_guardrail_binary-0.0.5-cp313-cp313-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp313-cp313-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 498.7 kB
- Tags: CPython 3.13, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94f9e276454182d6d8bee980a2ae04c6a6509a5d30ebd522c563acddbd10a885
|
|
| MD5 |
5b6bb722871bfae22f9a81de410270e6
|
|
| BLAKE2b-256 |
21649ac7128fc121eebf5a939244cca483f15bde7cffb70678c6dc8bb32631bd
|
File details
Details for the file gllm_guardrail_binary-0.0.5-cp313-cp313-macosx_13_0_arm64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp313-cp313-macosx_13_0_arm64.whl
- Upload date:
- Size: 289.0 kB
- Tags: CPython 3.13, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2592d20bb58290c035bc17ac2eb388d9b9487ecef572974343ae7cf8cacdc33c
|
|
| MD5 |
addf3813b3ce0ad18c3ec3208b46af8a
|
|
| BLAKE2b-256 |
d493bac0c2ca5868f2186a86bcf6df34bda5f25ac8f109af21cc05da18d44295
|
Provenance
The following attestation bundles were made for gllm_guardrail_binary-0.0.5-cp313-cp313-macosx_13_0_arm64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_guardrail_binary-0.0.5-cp313-cp313-macosx_13_0_arm64.whl -
Subject digest:
2592d20bb58290c035bc17ac2eb388d9b9487ecef572974343ae7cf8cacdc33c - Sigstore transparency entry: 855052405
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@da37679695af4ae02d3197d76f23499d2256abef -
Branch / Tag:
refs/tags/gllm_guardrail-v0.0.5 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@da37679695af4ae02d3197d76f23499d2256abef -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_guardrail_binary-0.0.5-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 339.3 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b44700a010e1b49e98aadfe924e5d797c4f68affe2f6431586bf0bff4e6ddca
|
|
| MD5 |
cef5641a72b9ed4726712913a5da89a8
|
|
| BLAKE2b-256 |
af38415b0d479bac0cb65ed3fa7ede12a7bb9fb11f9fea7d619cea900e8eafb1
|
Provenance
The following attestation bundles were made for gllm_guardrail_binary-0.0.5-cp312-cp312-win_amd64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_guardrail_binary-0.0.5-cp312-cp312-win_amd64.whl -
Subject digest:
2b44700a010e1b49e98aadfe924e5d797c4f68affe2f6431586bf0bff4e6ddca - Sigstore transparency entry: 855052388
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@da37679695af4ae02d3197d76f23499d2256abef -
Branch / Tag:
refs/tags/gllm_guardrail-v0.0.5 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@da37679695af4ae02d3197d76f23499d2256abef -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_guardrail_binary-0.0.5-cp312-cp312-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp312-cp312-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 501.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a33920fe3afd5767cfae52cec07ee83bc76e7f933d625d6ba3c736b200865d9
|
|
| MD5 |
b5aa941fef6b6dc51dc3adb2e3e0e122
|
|
| BLAKE2b-256 |
5ae221f6b0b9dfade64c04097c19ea62dee9fd96997cc3871300979d1b7d23d7
|
File details
Details for the file gllm_guardrail_binary-0.0.5-cp312-cp312-macosx_13_0_arm64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp312-cp312-macosx_13_0_arm64.whl
- Upload date:
- Size: 289.7 kB
- Tags: CPython 3.12, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2edea21b38969e63f91edffc3d21858c091ca7d26cc9061d5d6ca3c4a88a12d
|
|
| MD5 |
e92d074d8a8c4c92f0b1bad1f4ca29b7
|
|
| BLAKE2b-256 |
1296671466ef8d698f5d6da9688b5de50bf6ead83b12db39156f43829e0f3162
|
Provenance
The following attestation bundles were made for gllm_guardrail_binary-0.0.5-cp312-cp312-macosx_13_0_arm64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_guardrail_binary-0.0.5-cp312-cp312-macosx_13_0_arm64.whl -
Subject digest:
f2edea21b38969e63f91edffc3d21858c091ca7d26cc9061d5d6ca3c4a88a12d - Sigstore transparency entry: 855052432
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@da37679695af4ae02d3197d76f23499d2256abef -
Branch / Tag:
refs/tags/gllm_guardrail-v0.0.5 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@da37679695af4ae02d3197d76f23499d2256abef -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_guardrail_binary-0.0.5-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 342.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bd8c279a970fe79224f3dd0179f65d7959a521ae6f580415eef77337e032ec7
|
|
| MD5 |
acaf590cfe8bef60bd9d860c19bfd16d
|
|
| BLAKE2b-256 |
1eb37f5427faaabbb968300b4cd1774d3b66371892d5e49bf0759955bdcd4bdb
|
Provenance
The following attestation bundles were made for gllm_guardrail_binary-0.0.5-cp311-cp311-win_amd64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_guardrail_binary-0.0.5-cp311-cp311-win_amd64.whl -
Subject digest:
8bd8c279a970fe79224f3dd0179f65d7959a521ae6f580415eef77337e032ec7 - Sigstore transparency entry: 855052417
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@da37679695af4ae02d3197d76f23499d2256abef -
Branch / Tag:
refs/tags/gllm_guardrail-v0.0.5 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@da37679695af4ae02d3197d76f23499d2256abef -
Trigger Event:
push
-
Statement type:
File details
Details for the file gllm_guardrail_binary-0.0.5-cp311-cp311-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 464.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86554673f7bb566980a148fe4e00887865918e20e43dc28100b0d39932a5bf36
|
|
| MD5 |
23e4b682a1c2258b748769fe39c6f5d7
|
|
| BLAKE2b-256 |
32afad5af678f93185bf374cbfddb0cb70a535eb1ed4090cdbae563db1cff589
|
File details
Details for the file gllm_guardrail_binary-0.0.5-cp311-cp311-macosx_13_0_arm64.whl.
File metadata
- Download URL: gllm_guardrail_binary-0.0.5-cp311-cp311-macosx_13_0_arm64.whl
- Upload date:
- Size: 287.0 kB
- Tags: CPython 3.11, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d94d2e7de7f2d190ff15835bef017f45c88cad8df2add2ea4a18444f4a43b732
|
|
| MD5 |
6f0cec8c901bb7f3c77e0f62f983858a
|
|
| BLAKE2b-256 |
abd65d6042c950f719c843f4aeb258f61cef852663aeb69171b78471252576d7
|
Provenance
The following attestation bundles were made for gllm_guardrail_binary-0.0.5-cp311-cp311-macosx_13_0_arm64.whl:
Publisher:
build-binary.yml on GDP-ADMIN/gl-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gllm_guardrail_binary-0.0.5-cp311-cp311-macosx_13_0_arm64.whl -
Subject digest:
d94d2e7de7f2d190ff15835bef017f45c88cad8df2add2ea4a18444f4a43b732 - Sigstore transparency entry: 855052404
- Sigstore integration time:
-
Permalink:
GDP-ADMIN/gl-sdk@da37679695af4ae02d3197d76f23499d2256abef -
Branch / Tag:
refs/tags/gllm_guardrail-v0.0.5 - Owner: https://github.com/GDP-ADMIN
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-binary.yml@da37679695af4ae02d3197d76f23499d2256abef -
Trigger Event:
push
-
Statement type: