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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.13macOS 13.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.12macOS 13.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

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

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 224fde8896539b290b0232e5e7202f9591f063c780c8bcce3ff5280fd71f6bcc
MD5 0952a91941e73fd1388bde7b8166558f
BLAKE2b-256 61b59095601b6d0ae1fdb461bf6f23d8bdf8ec4f5856962a6d80ed5beb934842

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 53bf3605500f027781452f8b39446c8d85b39678c726266e234344f8dbd4a3cd
MD5 803340fab68dbd48b3d35712b8af1f02
BLAKE2b-256 508a636a44e6bc11482cb392e1da0ba0a4b4b1a2b5e20831e3c948518b1b00bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 bcd5cc9ba5df3fffda84f27e355f7a8a98cec68ac628337d149091a360f94836
MD5 f5957e986e3028ad08a01ca56c0adc1d
BLAKE2b-256 04218c53577764f09641920bbab68f483cdc18599f44300945a2cb50c9780ab6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 09e258a3ce4110b509470ff69edb52e4005790199bf7dda6268ed18c8b1c35c1
MD5 6c63ddace62b86ab191d08f427f49265
BLAKE2b-256 947d1ac75fe5c7643fd1d3ac3d2a82ac8c7d7067fc87ad6edeacc95f91a62288

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 75f05770587a8692d6256092d65f5608545ee48c5aaa214caa7c41fda90aab9d
MD5 4c4244b65d7bfa3fda9596713c732c5f
BLAKE2b-256 23bc71edf304d00b5e479fca9e66165d766dc01bfd6b570b4d3d762df245d77e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 f31f566a5834a192f816be0e5c57e7e4c9efbe71f4a6d1f08514aa8bb1a43577
MD5 5ad9c7ff074f9d261a1005e9bf84a51d
BLAKE2b-256 df46e3b2b2950d1a1b99cd3d0de693cf6c9c736b67068f0debbc08bb835f9776

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 05f6753282a9ae058b6002e1a1315146e7c33d7c6ca642921f7bfb4e6c1d0aec
MD5 6802952e199abdc9d757826779e8cb01
BLAKE2b-256 a76448ef691fbad082a89250eafe59f0413bba9bbc07d5f2ac64a31c6255ef1c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 bf2060d294af9e99b3d786ca1b7d0ee1b5202be636ddfa56709d21a00cb37546
MD5 663a1ff9834bfbab2c91d772968e888d
BLAKE2b-256 4966be5243f92437a6e080dc7ede4547be6fba4c5729bc9a69dacfeb1c526cfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gllm_guardrail_binary-0.0.7.post4-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 bc52b2abf6d5f9001ca893b9cb6afd44a5af1b47181997d75e5b9ce7a40b8ed3
MD5 552a55597dcb92d9beebd542f42bf1f2
BLAKE2b-256 7a44a7c553e5826e7e25aca6c9526f3a45ddf252e7229f8f5867ec4fc691e895

See more details on using hashes here.

Provenance

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