Skip to main content

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

Project description

Token Guardian

Python 3.12+ CLI License: MIT Tests

Token Guardian is a CLI-first guardrail for checking prompt size, context pressure, and estimated cost before you call an LLM.

It helps developers answer three questions quickly:

  • how many tokens this prompt will probably use
  • how much this request may cost
  • whether this prompt is risky for the selected context window

Preview

Token Guardian CLI analyze output

The current CLI interface is optimized for interactive terminal use and the guided experience is presented in pt-BR.

Why Use Token Guardian?

  • catch oversized prompts before they hit the model
  • estimate cost before expensive runs
  • compare supported models using the same prompt
  • clean duplicated or bloated prompt text
  • keep simple local observability with SQLite metrics
  • start from an interactive terminal menu instead of memorizing commands

Copy-Paste Install

Windows PowerShell

pip install token-guardian
token-guardian

macOS / Linux

pip install token-guardian
token-guardian

Running token-guardian without arguments opens an interactive menu when your terminal supports it.

What the CLI Can Do

  • analyze one prompt for one provider/model pair
  • compare one prompt across the default supported models
  • optimize prompt text by removing duplicates and excess whitespace
  • list supported models
  • sync the local model catalog snapshot
  • inspect local usage metrics
  • guide the full flow through an interactive menu

Usage

Start here

token-guardian

Running without arguments shows the available flow and the most useful commands to start with.

In interactive terminals, Token Guardian opens a guided menu with:

  • provider selection
  • model selection
  • prompt entry with Enter to send
  • sync selection by provider
  • quick access to models and metrics

Analyze a prompt

token-guardian analyze \
  --provider anthropic \
  --model claude-sonnet-4 \
  --prompt "Review this architecture proposal and identify risks."

Compare models

token-guardian compare \
  --prompt "Summarize this technical RFC and list migration risks."

Optimize a prompt

token-guardian optimize \
  --prompt "Goal: summarize
Goal: summarize


Return bullets only."

List supported models

token-guardian models

Sync model catalog

token-guardian sync-models
token-guardian sync-models --provider openai

View local metrics

token-guardian metrics

Example Output

Typical analyze output is rendered as a terminal report with token estimate, cost, context usage, risk, and prompt guidance.

Supported Providers

Current built-in catalog:

  • OpenAI: gpt-4.1
  • Anthropic: claude-sonnet-4, claude-opus-4
  • Google: gemini-2.5-pro, gemini-2.5-flash
  • OpenRouter: openai/gpt-4.1

Each model stores:

  • context limit
  • input price per 1K tokens
  • output price per 1K tokens
  • speed estimate
  • source URL

The CLI also shows catalog metadata such as:

  • Catalogo atualizado em 2026-06-13
  • the current JSON snapshot path

Scoring

Risk level

Based on estimated context usage:

  • low
  • medium
  • high
  • critical

Context health score

Range: 0 to 100

Factors include:

  • prompt size
  • repeated lines
  • repeated vocabulary
  • redundant sections

Cost score

  • $: very low
  • $$: low
  • $$$: medium
  • $$$$: high

Complexity score

  • Simple
  • Medium
  • Complex
  • Very Complex

Metrics

Token Guardian stores local metrics in SQLite.

Database file:

  • token_guardian.db

Tracked fields include:

  • total requests
  • total tokens
  • estimated cumulative cost
  • top models
  • top providers

Project Structure

token-guardian/
|-- app/
|   |-- cli.py
|   |-- models/
|   |-- providers/
|   |-- services/
|   `-- utils/
|-- docs/
|-- tests/
|-- LICENSE
|-- pyproject.toml
`-- README.md

Development

Run tests:

pytest

Run quality checks:

ruff check .
black --check .
mypy app

Roadmap

  • add richer interactive CLI flows
  • expand supported model catalog
  • improve prompt optimization heuristics
  • add exportable reports
  • add model catalog sync support

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.2.tar.gz (20.6 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.2-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file token_guardian-0.1.2.tar.gz.

File metadata

  • Download URL: token_guardian-0.1.2.tar.gz
  • Upload date:
  • Size: 20.6 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.2.tar.gz
Algorithm Hash digest
SHA256 73a46428bb56309c1b9896b733909e31f2c24e096fde7f1fd89536b849137579
MD5 46fe828b2096a6ea6e4e6cba4e674427
BLAKE2b-256 4c6e0e9ab95fb7262cf0eb031fdf1f4f15b40c1100a6382dd48f449246ec9300

See more details on using hashes here.

File details

Details for the file token_guardian-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: token_guardian-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for token_guardian-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99a8a54307b568396954662bc2f79facd7162955a9b0501870d70347cb1171f1
MD5 5a3f22f24650e794f3bb2396bc066fa4
BLAKE2b-256 1c10bb54c23c945bca25272ae3a06c46719ae44b84f71bc1dd19a0448ef469fb

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