llm-keyguard
Zero-dependency secret scanner, MCP configuration auditor, and <35ms Git pre-commit guard for LLM & AI API keys.
Modern AI engineering introduces new credential leak vectors beyond traditional web apps: developers frequently commit .mcp.json, .cursor/mcp.json, Jupyter notebooks, and agent configuration files containing live keys for OpenAI, Anthropic, Gemini, Groq, OpenRouter, Pinecone, LangSmith, HuggingFace, and ElevenLabs.
llm-keyguard is a pure-Python, zero-dependency CLI and library designed to stop AI credential leaks before they enter Git history—without requiring external Go binaries or Docker containers.
Features
- 20+ AI, Vector DB & Cloud Signatures + Shannon Entropy Filtering: Detects OpenAI (
sk-proj-,sk-svcacct-,sk-admin-), Anthropic (sk-ant-), Google Gemini (AIzaSy), Groq (gsk_), OpenRouter (sk-or-v1-), HuggingFace (hf_), Replicate (r8_), Perplexity (pplx-), Fireworks (fw_), Tavily (tvly-), Pinecone (pcsk_), LangSmith (lsv2_), ElevenLabs, Supabase, GitHub PATs, AWS IAM, Stripe Live, Slack, and PEM private keys while ignoring low-entropy placeholders. - Dedicated MCP Config Auditor (
audit-mcp): Parsesmcp.json,.mcp.json,.cursor/mcp.json, andclaude_desktop_config.jsonto pinpoint exact JSON paths (e.g.mcpServers.search.env.OPENAI_API_KEY) containing literal credentials instead of environment references. - One-Command Repository Hardening (
init): Automatically hardens.gitignore(blocking.envand key files while allowing.env.example) and installs a fast native Gitpre-commithook. - Safe
.env.exampleGenerator (env-example): Generates sanitized.env.exampletemplates from local.envfiles without exposing real credentials. - OASIS SARIF v2.1.0 Export (
--format sarif): Integrates directly with GitHub Code Scanning and CI pipelines.
Quickstart
pip install llm-keyguard
# 1. Harden .gitignore and install the Git pre-commit guard
llm-keyguard init
# 2. Scan your project directory (including MCP configs)
llm-keyguard scan .
# 3. Audit MCP configuration files specifically
llm-keyguard audit-mcp .
# 4. Generate a safe .env.example from your local .env
llm-keyguard env-example --source .env --output .env.example
Using with pre-commit
Add llm-keyguard to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/Edimilson22/llm-keyguard
rev: v0.2.0
hooks:
- id: llm-keyguard
GitHub Actions & Code Scanning (SARIF)
name: AI Credential Scan
on: [push, pull_request]
jobs:
keyguard:
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install llm-keyguard
- run: llm-keyguard scan . --format sarif > results.sarif || true
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
Python API
from pathlib import Path
from llm_keyguard import scan_path, audit_mcp_configs, build_sarif_report
findings = scan_path(Path("."))
for item in findings:
print(f"[{item.rule_id}] {item.file}:{item.line} -> {item.provider} ({item.masked})")
mcp_issues = audit_mcp_configs(Path("."))
sarif_payload = build_sarif_report(findings)
Inline Suppression
For intentional synthetic test fixtures, append # keyguard: ignore (or # pragma: allowlist secret) to the line:
TEST_FIXTURE = "sk-proj-..." # keyguard: ignore
License
MIT License. See LICENSE for details.
Metadata
Release files for llm-keyguard 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_keyguard-0.2.0.tar.gz | 17.5 kB | With provenance | Details for llm_keyguard-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_keyguard-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for llm_keyguard-0.2.0-py3-none-any.whl |
Total release size: 33.3 kB
Release files / llm_keyguard-0.2.0.tar.gz
| Download URL | llm_keyguard-0.2.0.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cac55397383d39ad63917c6ad26575bc3c832cdc523420fbcafde0ea853cc4cf
|
|
BLAKE2b-256 checksum How to use checksums |
da2345217c0b3cdbeb2068d94a892c249acdd5d35e7f95473c36538910e1cac8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / llm_keyguard-0.2.0-py3-none-any.whl
| Download URL | llm_keyguard-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d98ee97273b6bd44e5fd4eb2e9c3c96492aa22a60ab14b26c1be4cf633606ef
|
|
BLAKE2b-256 checksum How to use checksums |
6c193dda4008d2f31a45155c8a67b9d84f385189d67b54d9d5694fd62d1cc714
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for llm-keyguard 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for llm_keyguard-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.