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

Uploaded CPython 3.13Windows x86-64

gllm_guardrail_binary-0.0.7.post1-cp313-cp313-manylinux_2_31_x86_64.whl (544.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.7.post1-cp313-cp313-macosx_13_0_arm64.whl (324.1 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.7.post1-cp312-cp312-win_amd64.whl (370.0 kB view details)

Uploaded CPython 3.12Windows x86-64

gllm_guardrail_binary-0.0.7.post1-cp312-cp312-manylinux_2_31_x86_64.whl (546.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.7.post1-cp312-cp312-macosx_13_0_arm64.whl (323.9 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.7.post1-cp311-cp311-win_amd64.whl (374.7 kB view details)

Uploaded CPython 3.11Windows x86-64

gllm_guardrail_binary-0.0.7.post1-cp311-cp311-manylinux_2_31_x86_64.whl (503.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.7.post1-cp311-cp311-macosx_13_0_arm64.whl (320.2 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 67a96b5f5cb3f6b03ecc167570758a827655278f514cc966df20a0433a1baf17
MD5 4f0a09de02b8b7d53de3e9180a1825df
BLAKE2b-256 37c26d30528dbc89ec59b8a3943aaf3b4428e1decc49ad67cdf833e94b53574c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_guardrail_binary-0.0.7.post1-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.post1-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 ecf345c8cb2532d78c5e939eed11b5e59818b1d643615c2d510fee2ebb33e1a9
MD5 a3858b956d9519e87974ba9aa34e3206
BLAKE2b-256 c91447a983c181d537a02bd2c1ed9794ab3ab7fcd39463e8708dd25377a69512

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d4afe3a7f08db26d388440d710598dc999b8ceb896360a3881c33017941d01f3
MD5 64facee575412ff08a2630160aeed6a5
BLAKE2b-256 3d2527d5a717506be4cb12b284d592b2ec299b09e91063a6fc518098394c5872

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0451a30bb6ebe201ae9af9806ad2e6a2b39e3554877206c9491548e5943ddb00
MD5 50f4d05da160b92d68829f8e68db22a1
BLAKE2b-256 01d681b75d1ccfb32d80d1a5529d05c7f4acab0d5e673198aefe91730c40dc2d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 28eff7e2c26212bbce14a16ed289ac39acf6a324f408e0626d656a14d799c08b
MD5 102c13c9a1c3b63a3adcac7c0c64f150
BLAKE2b-256 f9665441ba0a801fa1bcd238f615c7899444235feab901f830b81d83af60979c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 7437b42d280fc78b08e11dfe8f73a72ddfd6711786d99530c936cd9e1fa92d1e
MD5 147b71f2e61dee31293f7ac6c73fdc07
BLAKE2b-256 b46c41eac22bff1c31bac1b68b512621aa52186f0db9571fab9322fbd141af69

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d33b32b7557d6bf58c69d9655f48385767613dbd354105cc3d797f9b1d1986b0
MD5 37919b5ad0863646bf21fb0fc6a334c1
BLAKE2b-256 e878ee7ff5a8d43e0bf8191f80eba32950a51336c3fc1875e54532c96e3e4d3f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 bd6a7a71ac1276e75c4d4b2c42f540bcd5de5b04685479240c20b4c1d67af196
MD5 a8eb248b1b7e0ed371d0a8f35cd691f4
BLAKE2b-256 6a0f22ad91a70dd17b2d4a291f123b91b2227059f86adbddcde45b7d1a78a9f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post1-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 c04479ebf750917f7f7afbd377794e4d25bfa3a0059a4333c9a13e7046ee28a2
MD5 4d61036e31026d50a389ce17a383703a
BLAKE2b-256 7083809cfb8a86471820963587871cb6599ebe116dded45131615ba9f005dd65

See more details on using hashes here.

Provenance

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