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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.13macOS 13.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.12macOS 13.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 98c712005b162d2a20c577232e5c54a1aef84e3609d7db2305d27bf87208076d
MD5 870890a15a36b25e562c3e67c68ce3b1
BLAKE2b-256 c96b0ae3431f3ed81b98107731c8f5ba1c06e1de02b260f8fcfe622ab051775d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 0bd2fe41f5ffb688d7df9e95e42e77a69d7195bb33b1b8ddfcdd64fdb7c4f991
MD5 3769a372ba0236ff83d23e9f84e9c862
BLAKE2b-256 cb8dfe7c286a79b5f921fcbbe0c52c731eae2dab7f158a317449ff3980ec381d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 624b62c984697c39452a18b2d05d3c8941db1816666dcbbfae9a3fce3276c04b
MD5 7d89948a403aff94ac07202f42905da9
BLAKE2b-256 67bd8066c9101cd2855e679b56bcee600babebcb0e6e74fa805b5713be0ae662

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f9bbad9606f253ed0d2e537aa4b4728baf27753e412aafb015871babd780bb7c
MD5 9fee7b75835728bf7b37a4698e68f3e1
BLAKE2b-256 38320f49eaa3c53857dd16c3cc84f130fffa3748d9af903427f4198d8ff69d4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 ea9bb8773588c2beadcd030809264c708134cc0466524f400ff9141c063e5454
MD5 bb3f16bd42d61408f697c1283dc90ffa
BLAKE2b-256 4be15f3a2149cca959516af1ef78eb25a157c8ff947b66fe1391002961be9146

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 241c061ff8cb1f29d0b47a95a9263c41806738b4ab3a32de9bb8ec753f21fdd0
MD5 e82d668451bb8fa47ee76cfd7680f347
BLAKE2b-256 814d86557cfdcfd83b6c1f8f56ccb8cae89e75d3f6e5ed67dd93a47ea1497574

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f0119c6c8571ecb8928ba2ce793c151b5350569c2e3a72bb7ffddf61491d2970
MD5 57dc6ebc4f5e2a6b7aa4e05b4b166e2a
BLAKE2b-256 a755c28c082fac735784d1a35782a5c0609acb79a596b3e61284c6642bbf8ded

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 c9846cda8702ead93d1a06f8f802c355e14d68dc5dd984df5f5e1bac0de5b910
MD5 91b94b1d1cf5bcd9600bab629779537a
BLAKE2b-256 ddd263efd579ba353514f4476d039f9b9c125a0963af1a04adfe87410d230937

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post2-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 a919a152705229a25c0822bac5d53657ba73d55db6cf47778ef0dde897472e5b
MD5 4532a7b7af344d9c072d0b3be57f234e
BLAKE2b-256 9f419ac64c914925d76c82d82867f6da87f60ca2858ae0d073edb74e230967a4

See more details on using hashes here.

Provenance

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