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

Uploaded CPython 3.13Windows x86-64

gllm_guardrail_binary-0.0.5-cp313-cp313-manylinux_2_31_x86_64.whl (498.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.5-cp313-cp313-macosx_13_0_arm64.whl (289.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.5-cp312-cp312-win_amd64.whl (339.3 kB view details)

Uploaded CPython 3.12Windows x86-64

gllm_guardrail_binary-0.0.5-cp312-cp312-manylinux_2_31_x86_64.whl (501.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.5-cp312-cp312-macosx_13_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gllm_guardrail_binary-0.0.5-cp311-cp311-win_amd64.whl (342.8 kB view details)

Uploaded CPython 3.11Windows x86-64

gllm_guardrail_binary-0.0.5-cp311-cp311-manylinux_2_31_x86_64.whl (464.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gllm_guardrail_binary-0.0.5-cp311-cp311-macosx_13_0_arm64.whl (287.0 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ead3ba78daaacf14ade5bcc46b31fe39aea366bbf88e73935b151636060d5447
MD5 2eca8d7047608854b34ff754cbb42628
BLAKE2b-256 e7a2a1c6e99521dcfd216b670b690324c61221ba5508e2d8389c9960ea11cdad

See more details on using hashes here.

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

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.5-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 94f9e276454182d6d8bee980a2ae04c6a6509a5d30ebd522c563acddbd10a885
MD5 5b6bb722871bfae22f9a81de410270e6
BLAKE2b-256 21649ac7128fc121eebf5a939244cca483f15bde7cffb70678c6dc8bb32631bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 2592d20bb58290c035bc17ac2eb388d9b9487ecef572974343ae7cf8cacdc33c
MD5 addf3813b3ce0ad18c3ec3208b46af8a
BLAKE2b-256 d493bac0c2ca5868f2186a86bcf6df34bda5f25ac8f109af21cc05da18d44295

See more details on using hashes here.

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

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.5-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2b44700a010e1b49e98aadfe924e5d797c4f68affe2f6431586bf0bff4e6ddca
MD5 cef5641a72b9ed4726712913a5da89a8
BLAKE2b-256 af38415b0d479bac0cb65ed3fa7ede12a7bb9fb11f9fea7d619cea900e8eafb1

See more details on using hashes here.

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

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.5-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 3a33920fe3afd5767cfae52cec07ee83bc76e7f933d625d6ba3c736b200865d9
MD5 b5aa941fef6b6dc51dc3adb2e3e0e122
BLAKE2b-256 5ae221f6b0b9dfade64c04097c19ea62dee9fd96997cc3871300979d1b7d23d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 f2edea21b38969e63f91edffc3d21858c091ca7d26cc9061d5d6ca3c4a88a12d
MD5 e92d074d8a8c4c92f0b1bad1f4ca29b7
BLAKE2b-256 1296671466ef8d698f5d6da9688b5de50bf6ead83b12db39156f43829e0f3162

See more details on using hashes here.

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

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.5-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8bd8c279a970fe79224f3dd0179f65d7959a521ae6f580415eef77337e032ec7
MD5 acaf590cfe8bef60bd9d860c19bfd16d
BLAKE2b-256 1eb37f5427faaabbb968300b4cd1774d3b66371892d5e49bf0759955bdcd4bdb

See more details on using hashes here.

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

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.5-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 86554673f7bb566980a148fe4e00887865918e20e43dc28100b0d39932a5bf36
MD5 23e4b682a1c2258b748769fe39c6f5d7
BLAKE2b-256 32afad5af678f93185bf374cbfddb0cb70a535eb1ed4090cdbae563db1cff589

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.5-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d94d2e7de7f2d190ff15835bef017f45c88cad8df2add2ea4a18444f4a43b732
MD5 6f0cec8c901bb7f3c77e0f62f983858a
BLAKE2b-256 abd65d6042c950f719c843f4aeb258f61cef852663aeb69171b78471252576d7

See more details on using hashes here.

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

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