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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.13macOS 13.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.12macOS 13.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 58c6d4e2b965fef63c56f8c58740aac90356d6a7279e9cea62c20dd03320244a
MD5 07ad466f578ea9d394213bc2fbd5415d
BLAKE2b-256 19d0077eb60e338e52a71e5b0c717fe570b1d6ce5076f9f2bbb8f0fa1f907e2a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 3b160fd8ac8c9c6938fad9a28875f7d83f2f41b74ee0ba3d5986af7dd20617a5
MD5 95b023e71378c26017aeea8c724e66c7
BLAKE2b-256 90b9db291386c6901269faaafa2ba90b484a313c717d49605d1fd1ef07c8c7d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 1f94e1a36b42c300e2a43c6979696592345f001eb411913ded113ff57e292a45
MD5 3519315af6de0c8788a5227a9736b5e4
BLAKE2b-256 9897b229b33bed5dca0349f0f2924e29a5fb1135b023070f1b368d45b632c369

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 964d38fe1f008fe8d8042a41f900f1e81fdb6c3d00780cfe55f67125d5b04a7a
MD5 d8825fd8d4c0b405028b890df823b2d1
BLAKE2b-256 0a37e321765a927ba4d0b05c856c42d49205f27b2da9c2ef10dae694d15ef99b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 8cdaaa54219891dd934b8da204febc73d15031da5bbd0dc6238e873419866209
MD5 3f2c05b9918639feae3999bb96caf354
BLAKE2b-256 957ec7e560e6f8661bbf9d8bb4c2cfc53b6d2b4b95a7953f70232c3bf3050b5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 755c3c8788f51bbb86220392ea362893f8be0daeda71be678b164bbbbdeb861a
MD5 ed2e654dc2f3aeeba060aa03320ac763
BLAKE2b-256 850d6631166f9a2cf6ed8330e66bb41ce9c66dc0af64d7370a2d44e0cbbaf39c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0c601163a0d34bcfb4e6fbe19e70c0a6b1a5320c747b502308fdaa86352a360a
MD5 cfe387ff3c265668c7ab46ec61cf25cc
BLAKE2b-256 0aa0d5b04fc6ff7283f7366b22cd239b419055434816607319dc2a852e6a49a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 de82fd7beeb82f025ec9e07a99e2007681ac72c78affb37cded14765d0b34a43
MD5 89e7388c92ca846c73222c405529a7be
BLAKE2b-256 91bbd3720b2f0267b379ea62612fdc16db56fe511f7fa98ca2089740bc64302b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 cae086879faf20a592686fd2f8c2e5fda71521aed551730618fc9747989d3158
MD5 68c8ec95cb20078bfac6fe80a9955c1d
BLAKE2b-256 4913f11b95ee4f9714a2d41bb0bdd7ed6bdc67c46a336170af39c57ad9be8811

See more details on using hashes here.

Provenance

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