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.6-cp313-cp313-win_amd64.whl (338.0 kB view details)

Uploaded CPython 3.13Windows x86-64

gllm_guardrail_binary-0.0.6-cp313-cp313-macosx_13_0_arm64.whl (290.6 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.6-cp312-cp312-win_amd64.whl (340.4 kB view details)

Uploaded CPython 3.12Windows x86-64

gllm_guardrail_binary-0.0.6-cp312-cp312-manylinux_2_31_x86_64.whl (504.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.6-cp312-cp312-macosx_13_0_arm64.whl (291.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.6-cp311-cp311-win_amd64.whl (344.3 kB view details)

Uploaded CPython 3.11Windows x86-64

gllm_guardrail_binary-0.0.6-cp311-cp311-manylinux_2_31_x86_64.whl (467.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.6-cp311-cp311-macosx_13_0_arm64.whl (288.7 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file gllm_guardrail_binary-0.0.6-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c483ac950cf1404659b229721f87d92393f082f1fa800666ac4b5cc1e87d6937
MD5 784a4c7b68c3ab390f7d722da510c52d
BLAKE2b-256 183ec670795db7accef1cd36154db0208b684162801a50927dbf875baf55b2f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.6-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.6-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 b9cb60554817f6d862102fe5d9299104be8f3e8669eced0573fe71a728e977df
MD5 047891d1f45b6404440c5f19d18bdc11
BLAKE2b-256 5be660ed46d842283665de98fb7d48775158bf2c148162b03b8bb9e73836ab28

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.6-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.6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5938be2b2a9a7fdea5757329ffc344dd392f203ab7053188299584fb6220259b
MD5 cb5f044e277810974ca65000739f583d
BLAKE2b-256 e28a00d114b2bc1e7961f223efe1dfd47ddef7fa2fd36ba9768a238854309b69

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.6-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.6-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 c5a23ff99dd9e90a873a0fd504f272e403928b95d90184c8a72c71895c20b478
MD5 8ea9ea48f2415cd4f91e1830bde862fa
BLAKE2b-256 536dbb3ddd54a1e534df99417acc826a8f98e2fb4079c030c4c31f2a2c3dd397

See more details on using hashes here.

File details

Details for the file gllm_guardrail_binary-0.0.6-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 810aca7d66816513f2b6612051bfa5a6840972a3835d80fcf8ddea83d85714da
MD5 fd77cd20c70f8e098b50cefd603949e6
BLAKE2b-256 b26d91f5e66860ee14d1e645ef3970fb044806b68a01f2265feb0b8d60d72dd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.6-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.6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 28562ed9e1e390390e52e1a16e1906e5c0e72f39937595d87b2787a49f313458
MD5 d4aef28af6a346d02cc70b19a8eedbed
BLAKE2b-256 7bc4c7f7af36a6b41d376167e011856f41cf4cd770584381c1055799a105feea

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.6-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.6-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 be626df42abb1a37e23e91eff5524643f40804747f5a14f3abef87dfb65074fb
MD5 ef4f9c8daa00569d9378c012bf715168
BLAKE2b-256 93b692a8e379e428c72a903e779ea02ecc9b62c79bbf02b8bbcf315190a218d9

See more details on using hashes here.

File details

Details for the file gllm_guardrail_binary-0.0.6-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.6-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 5a47420f8e40198bbf537034842e4d5604594b9642f99d327ba8fe371f7d100a
MD5 0d84aad5fb997847bdd4c33abd2e2bf3
BLAKE2b-256 a594c1cff05519eb04d1f81f9ce4db98c4cd284a6163ebccb8556acbe1d7088a

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.6-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