Skip to main content

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:

  1. Python 3.11+ — Install here
  2. pip — Install here
  3. uv — Install here

Extras (required only for Artifact Registry installations):

  1. 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

  1. Python 3.11+ — Install here

  2. pip — Install here

  3. uv — Install here

  4. gcloud CLI — Install here, then log in using:

    gcloud auth login
    
  5. Git — Install here

  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gllm_guardrail_binary-0.0.7.post3-cp313-cp313-win_amd64.whl (303.3 kB view details)

Uploaded CPython 3.13Windows x86-64

gllm_guardrail_binary-0.0.7.post3-cp313-cp313-manylinux_2_31_x86_64.whl (546.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.7.post3-cp313-cp313-macosx_13_0_arm64.whl (333.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.7.post3-cp312-cp312-win_amd64.whl (303.8 kB view details)

Uploaded CPython 3.12Windows x86-64

gllm_guardrail_binary-0.0.7.post3-cp312-cp312-manylinux_2_31_x86_64.whl (547.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.7.post3-cp312-cp312-macosx_13_0_arm64.whl (333.2 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.7.post3-cp311-cp311-win_amd64.whl (312.3 kB view details)

Uploaded CPython 3.11Windows x86-64

gllm_guardrail_binary-0.0.7.post3-cp311-cp311-manylinux_2_31_x86_64.whl (503.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.7.post3-cp311-cp311-macosx_13_0_arm64.whl (329.6 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1191738ca8e470e27edbb9c720dcaa135a6f36067e96a2694a04653a303bb3bc
MD5 0651fefca1b5b9b59e6e7f031f785260
BLAKE2b-256 44c3f056379e2dfd9cf515775bf7d73f7c10bd1879c75493ae282f0a0fd27886

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post3-cp313-cp313-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 647e59a05e0acc859cf23164f83e8d380036e956fe64ed7deb9fa5f467b0279e
MD5 aac83f649a0c4042738e819effaabe87
BLAKE2b-256 e07b80fbb559f4bd4b56ed7d9a728175810c3d6e0f27b611651f01d0d096444f

See more details on using hashes here.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 263a90f66e06a67d6c56a075f138f9074e2c65633f6d5bd1199154b9757ca887
MD5 3fd84fe2f160d5d0c8509516590df7ef
BLAKE2b-256 d149133203bf3e0de76cd0f7ba36aadcb987383573f4511c059d5a79a9826a40

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post3-cp313-cp313-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 707922339ca21b44188d11c8eb68915e738be3cb6c72286a6c2184ca49bdb1f3
MD5 3410908512d09cb9036305c08cbf1e11
BLAKE2b-256 fb1d7585797a87e37ecb3967a160687e511759ea3aa6044037bb69d479443125

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post3-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 8233395a062687f49088a835866eeea0f2572cef2f3c5e1aac5a5a28a40ba3f5
MD5 4a8bc0f63c9b3ab71de245a68af03ff8
BLAKE2b-256 6f6e35521dad00ddb5e9fa516bdc60e303d1b13c6d6a80950ee4e574f0d4b245

See more details on using hashes here.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 3e5fba438d46aef2755ae73b0d9da1e2277968419aa33026354afc49e756fb5b
MD5 cb752258537eeafdabfd3131249f1ebe
BLAKE2b-256 12452aee6e6937e30470ca8d479da74eb75ffc2b9cf8f00505de6012dc175452

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post3-cp312-cp312-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8da53311fdea4b6c968a9c0c36b455d0470f2aa54b44f64b350220408e8e39d1
MD5 a7bb1c88f8e786ddefa82b5b7ec3148d
BLAKE2b-256 d552db181c18bd968274ff6290253397237b4d31f37cb07b6d2222861a732d45

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post3-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5d8ffd0e7c6292230a539eea6a0e30b3e47b4eed357d7a4d54cd45a7b6439a8f
MD5 750305b8b129a1e7d901827d0b77eafc
BLAKE2b-256 dc385379e3ec758f82e791ebaa6c7055b0966528951195b58db9791d0085ad2f

See more details on using hashes here.

File details

Details for the file gllm_guardrail_binary-0.0.7.post3-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post3-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 c1c570e715f6f6626bd1afd9d695ae35fbbae5333c9f2bdd72c5d812062b77f5
MD5 ee81fb29a7ac690f27a8f7a7c4f215f1
BLAKE2b-256 e9c7d77c5019783b4333da3a1a7fe32004d3c3aead848bd8752b2e1188406acc

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post3-cp311-cp311-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page