Skip to main content

CLI-first guardrail for prompt token, cost, and context observability.

Project description

Token Guardian

Token Guardian is a CLI-first preflight guardrail for LLM prompts.

   _______    _                 _____                     _ _
  |__   __|  | |               / ____|                   | (_)
     | | ___ | | _____ _ __   | |  __ _   _  __ _ _ __ __| |_  __ _ _ __
     | |/ _ \| |/ / _ \ '_ \  | | |_ | | | |/ _` | '__/ _` | |/ _` | '_ \
     | | (_) |   <  __/ | | | | |__| | |_| | (_| | | | (_| | | (_| | | | |
     |_|\___/|_|\_\___|_| |_|  \_____|\__,_|\__,_|_|  \__,_|_|\__,_|_| |_|

                            [ shielded prompt preflight ]

Before any real model call, it shows:

  • estimated tokens
  • estimated cost
  • context usage
  • context risk
  • prompt reduction hints

Then it shows the analysis before the execution flow continues.

Preview

Token Guardian opens with an interactive terminal flow that lets developers choose a host profile, select a model, submit a prompt, and inspect the preflight analysis before any real LLM call.

Release Status

Current release: 0.1.0-beta.1

This project is ready for early adopters who want to test a prompt guardrail in real workflows. It is not yet positioned as a fully hardened enterprise product.

What It Is

Token Guardian helps developers inspect a prompt before it reaches an LLM.

It is designed to answer three questions quickly:

  • how many tokens this prompt is likely to use
  • how much this prompt may cost
  • whether this prompt is too large, noisy, or risky for the selected model context

Who It Is For

  • developers using LLMs in daily coding workflows
  • teams that want a simple prompt review step before execution
  • open-source users who want a local, cross-platform CLI

What It Does Not Do

  • it does not intercept every editor chat automatically
  • it does not enforce organization-wide policy remotely
  • it does not replace provider-side safety systems
  • it does not depend on MCP or VS Code integration as a product requirement

Why CLI First

This is the most reliable way to enforce a real preflight gate:

  • it works on Windows, macOS, and Linux
  • it does not depend on editor-specific chat hooks
  • it always shows the analysis before any real LLM call
  • it is easy to share with other developers

Install

Windows

powershell -ExecutionPolicy Bypass -File scripts\install.ps1

macOS / Linux

bash scripts/install.sh

Run

Windows

powershell -File scripts\run-cli.ps1

macOS / Linux

bash scripts/run-cli.sh

You can also run the command directly:

token-guardian

What the menu does

When the CLI opens, you get a simple menu:

  1. revisar prompt
  2. revisar prompt e enviar para LLM
  3. ver metricas
  4. listar modelos suportados
  5. sair

The intended flow is:

  1. choose the host profile such as Claude Code, Codex, or GitHub Copilot
  2. choose a suggested model for that profile
  3. paste the prompt and press Enter
  4. inspect the markdown analysis
  5. if you are in execution mode, Token Guardian continues to the LLM automatically

In the interactive terminal flow, selections use espaco to mark and Enter to confirm.

Prompt UX in the current menu:

  • the prompt is entered in a single step
  • Enter sends the prompt
  • output token estimation is automatic in the interactive flow

Main commands

The interactive menu is the default, but advanced commands are still available:

token-guardian
token-guardian menu
token-guardian models
token-guardian metrics
token-guardian review --provider anthropic --model claude-sonnet-4 --prompt "Revise esta arquitetura."
token-guardian run --provider anthropic --model claude-sonnet-4 --prompt "Revise esta arquitetura."

Real LLM invocation

If you want Token Guardian to call the provider after the analysis step, install the gateway extra:

pip install -e .[gateway]

Then use:

token-guardian run --provider anthropic --model claude-sonnet-4 --prompt "Revise esta arquitetura."

The run flow analyzes first and then calls the LLM directly.

Metrics and observability

Token Guardian stores local usage data in SQLite.

Tracked data includes:

  • total requests
  • total tokens
  • estimated cumulative cost
  • most used models
  • most used providers

Database file:

  • token_guardian.db

To inspect metrics:

token-guardian metrics

Supported models

See the live list from the CLI:

token-guardian models

Developer commands

Run the full test suite:

pytest

License

MIT

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

token_guardian-0.1.0b1.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

token_guardian-0.1.0b1-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file token_guardian-0.1.0b1.tar.gz.

File metadata

  • Download URL: token_guardian-0.1.0b1.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for token_guardian-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 4f176b65595f12c2092444dd608c8796d943c8449cb9a57ae66f8f17a10afa74
MD5 d99683548c79e42dcf06276d28db5aa5
BLAKE2b-256 b6c8136e35373b33e3b8e3b7b7d74642e0690e8b37d08dadecdedd02fc654a63

See more details on using hashes here.

File details

Details for the file token_guardian-0.1.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for token_guardian-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 ebc14d7aabc0dab12cadaae1beb342a838b4cde68675a0d232cfdeae3187e3d1
MD5 99971bf8da5bbe18a5914933ad4c192a
BLAKE2b-256 d3af97582ce037dbd174d8ae0006f195ed8e74808670a1a89a45f8c00fbac731

See more details on using hashes here.

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