Skip to main content

Governance Engine by zeb labs

Project description

Z-GRC

Governance, Risk, and Control Engine for LLMs

Built by Zeb Labs

Z-GRC Application PyPI Python Version Code Style: Ruff Built by Zeb Labs


Enterprise-grade governance engine for Large Language Model applications. Provides automatic interception, policy enforcement, quota management, and comprehensive observability across multiple LLM providers with zero code changes.

Installation

uv add z-grc

Or with auto-instrumentation:

uv add z-grc[auto-instrument]

Quick Start

AWS Bedrock Example

import zgrc
import boto3
import json

# Initialize GRC
zgrc.init(api_key="your-zgrc-api-key")

# Use your LLM SDK normally - GRC handles everything
client = boto3.client("bedrock-runtime", region_name="us-east-1")

response = client.invoke_model(
    modelId="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
    body=json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "max_tokens": 1024,
        "messages": [{"role": "user", "content": "Hello!"}]
    })
)

OpenAI Example

import zgrc
from openai import OpenAI

# Initialize GRC
zgrc.init(api_key="your-zgrc-api-key")

# Use OpenAI SDK normally
client = OpenAI(api_key="your-openai-key")

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Z-GRC automatically:
# - Validates quota before requests
# - Tracks token usage and calculates costs
# - Enforces policies
# - Sends telemetry (traces, metrics, logs)

Features

Zero-Code Integration

Drop-in solution requiring only zgrc.init(). Works with existing code without modifications.

Auto-Discovery

Automatically detects and intercepts installed LLM SDKs:

  • AWS Bedrock (boto3)
  • OpenAI (including Azure OpenAI, Databricks, and OpenAI-compatible endpoints)
  • Anthropic (coming soon)

Policy Enforcement

Real-time quota validation and cost limit enforcement. Blocks requests when quota is exceeded.

from zgrc.utils import QuotaExceededException

try:
    response = client.invoke_model(...)
except QuotaExceededException as e:
    print(f"Quota exceeded: ${e.used:.4f} used, ${e.remaining:.4f} remaining")

Quota Exceeded Example

Auto-Instrumentation

Optional automatic instrumentation for HTTP clients, web frameworks, databases, and more:

zgrc.init(
    api_key="your-zgrc-api-key",
    auto_instrument=True,
    app_name="my-app",
    environment="production"
)

Framework Agnostic

Works with vanilla SDKs and popular frameworks:

# PydanticAI
from pydantic_ai import Agent
agent = Agent("bedrock")
result = await agent.run("Your prompt")

# LangChain
from langchain_aws import ChatBedrock
llm = ChatBedrock(model_id="...")
response = llm.invoke("Your prompt")

# Strands Agents
from strands_agents import Agent
agent = Agent(provider="bedrock")
response = agent.execute("Your prompt")

Streaming Support

Fully supports streaming responses with automatic token tracking:

response = client.converse_stream(
    modelId="...",
    messages=[{"role": "user", "content": [{"text": "Tell me a story"}]}]
)

for event in response["stream"]:
    if "contentBlockDelta" in event:
        print(event["contentBlockDelta"]["delta"]["text"], end="")

Configuration

zgrc.init(
    api_key: str,                  # Your Z-GRC API key (required)
    verbose: bool = False,         # Enable debug logging (default: False)
    auto_instrument: bool = False, # Enable auto-instrumentation
    app_name: str = None,          # Application name for telemetry
    environment: str = None        # Environment (dev/staging/prod)
)

Proxy Mode (Claude Code CLI)

For environments where code modification isn't possible (like Claude Code CLI), use the standalone proxy:

Quick Start

Background Mode (Recommended):

In the same terminal, run both commands:

# Step 1: Start proxy in background and set environment variables
eval $(z-grc-proxy --api-key=your-key -d)

# Step 2: Run Claude Code in the same terminal
claude

Claude Code Running with Z-GRC Proxy
Claude Code running with Z-GRC proxy in background mode

Note: You need to run the eval $(z-grc-proxy ...) command in every new terminal where you want to use Claude Code with Z-GRC. The environment variables only apply to the current terminal session.

Foreground Mode:

Terminal 1 - Start the proxy (shows logs):

z-grc-proxy --api-key=your-key

Z-GRC Proxy Running in Foreground
Proxy server running in foreground with request logs

Terminal 2 - Open another tab, set environment variables, and run Claude:

# Mac & Linux
export HTTPS_PROXY=http://127.0.0.1:8080
export NODE_EXTRA_CA_CERTS=~/.mitmproxy/mitmproxy-ca-cert.pem

# Windows
$env:HTTPS_PROXY = "http://127.0.0.1:8080"
$env:NODE_EXTRA_CA_CERTS = "$env:USERPROFILE\.mitmproxy\mitmproxy-ca-cert.pem"

# then run any cli application
claude

Note: In foreground mode, the proxy runs in Terminal 1 and shows live logs. Claude Code runs in Terminal 2 with the environment variables set to use the proxy.

Proxy Commands

# Mac & Linux Start in background (auto port detection)
eval $(z-grc-proxy --api-key=your-key -d)

# Windows Start in background (auto port detection)
z-grc-proxy --api-key=your-key -d | Out-String | Invoke-Expression

# Mac & Linux Start on specific port
eval $(z-grc-proxy --api-key=your-key --port=8085 -d)
# Windows
z-grc-proxy --api-key=your-key --port=8085 -d | Out-String | Invoke-Expression

# Check active proxy sessions
z-grc-proxy --status

# Kill all proxy servers
z-grc-proxy --kill-all

# Verbose logging
eval $(z-grc-proxy --api-key=your-key -d --verbose)

How It Works

  1. Automatic Port Detection: Finds available port (8080-8090)
  2. Session Management: Reuses existing proxy for same API key
  3. mitmproxy Certificates: Auto-generated in ~/.mitmproxy/ on first run
  4. Platform Independent: Works on macOS, Linux, Windows

Building Executables

Build standalone proxy binary with PyInstaller:

# Current platform only
make grpc-proxy-build

Output: dist/z-grc-proxy

Test Binary

# Background mode
eval $(./dist/z-grc-proxy --api-key=your-key -d)

# Foreground mode
./dist/z-grc-proxy --api-key=your-key

Installing Executor

macOS / Linux

curl -fsSL https://raw.githubusercontent.com/zeb-ai/z-grc/main/install.sh | bash

Windows (PowerShell)

irm https://raw.githubusercontent.com/zeb-ai/z-grc/main/install.ps1 | iex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z_grc-0.0.36.tar.gz (41.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

z_grc-0.0.36-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file z_grc-0.0.36.tar.gz.

File metadata

  • Download URL: z_grc-0.0.36.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for z_grc-0.0.36.tar.gz
Algorithm Hash digest
SHA256 11d5d6693245313802a76fa977ac31f162de4d805e096d026dd251fac8fb83bd
MD5 d6d3dddb27992c3ddc8ac245351319d6
BLAKE2b-256 61c6be93a8407d9c047df5f45069bd1d7c94c61d816dbcb2278949d8f4b5fa0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for z_grc-0.0.36.tar.gz:

Publisher: publish.yml on zeb-ai/z-grc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file z_grc-0.0.36-py3-none-any.whl.

File metadata

  • Download URL: z_grc-0.0.36-py3-none-any.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for z_grc-0.0.36-py3-none-any.whl
Algorithm Hash digest
SHA256 5f76185709318b37596e4999de45b086b24e9353c00d7e45c27e48248bd8e385
MD5 9c0c139e645789ea325c51ac3783a979
BLAKE2b-256 a6b6f202d2d54e7081a6bc36f0cf0a8c5ec1be3a266942ec0bf75137019cdff4

See more details on using hashes here.

Provenance

The following attestation bundles were made for z_grc-0.0.36-py3-none-any.whl:

Publisher: publish.yml on zeb-ai/z-grc

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