Skip to main content

ML-powered prompt complexity analyzer for LLM routing

Project description

prompt-complexity-analyzer

ML-powered prompt complexity analyzer for LLM routing. Scores any prompt 1–10 and recommends the right model tier — no API calls, runs locally.

Install

pip install prompt-complexity-analyzer

Quick start

from prompt_complexity_analyzer import complexity

r = complexity("prove P≠NP")
print(r.score)    # 9.2
print(r.tier)     # capable
print(r.model)    # claude-opus-4-6
print(r)          # Score 9.2/10 | Tier: capable | Model: claude-opus-4-6 | Backend: ml
r.explain()       # full breakdown with dimension scores

Score tiers

Score Tier Models
1.0 – 3.5 fast claude-haiku-4-5 · gpt-4o-mini · gemini-2.0-flash
3.6 – 6.5 balanced claude-sonnet-4-6 · gpt-4o · gemini-2.0-pro
6.6 – 10.0 capable claude-opus-4-6 · o1 · gemini-2.5-pro

Providers

r = complexity("your prompt", provider="openai")    # gpt-4o-mini / gpt-4o / o1
r = complexity("your prompt", provider="google")    # gemini-2.0-flash / pro / 2.5-pro
r = complexity("your prompt", provider="ollama")    # qwen3:1.7b / 14b / 32b
r = complexity("your prompt", provider="anthropic") # default

Result object

r = complexity("Compare ECDH vs RSA for TLS 1.3")

r.score          # float 1–10
r.tier           # "fast" | "balanced" | "capable"
r.model          # recommended model string for the chosen provider
r.label          # "Fast / Lightweight" | "Balanced" | "High Capability"
r.backend        # "ml" | "heuristic"
r.dimensions     # {"Reasoning Depth": 8.5, "Domain Specificity": 9.0, ...}
r.flags          # advisory messages, e.g. ["⚠ Very high complexity"]

# Fuzzy key access — substring matches dimension names
r["reasoning"]   # Reasoning Depth score
r["domain"]      # Domain Specificity score
r["multi"]       # Multi-part score
r["ambiguity"]   # Ambiguity score
r["output"]      # Output Complexity score

# Serialization
r.to_dict()      # plain dict
r.to_json()      # JSON string

explain() output

  ────────────────────────────────────────────────────────────
  Score        8.1 / 10
  Tier         High Capability
  Model        claude-opus-4-6  [anthropic]
  Backend      ml
  Use when     Complex research, deep reasoning, ambiguous high-stakes tasks
  ────────────────────────────────────────────────────────────

  Dimension                Bar               Score
  ──────────────────────────────────────────────────────────
  Vocabulary               ████░░░░░░░░░░     4.5
  Multi-part               ████████░░░░░░     7.0
  Reasoning Depth          █████████░░░░░     8.5
  Domain Specificity       █████████░░░░░     9.0
  Ambiguity                ███░░░░░░░░░░░     2.0
  Output Complexity        █████░░░░░░░░░     4.5

CLI

# Full breakdown
prompt_complexity_analyzer -p "your prompt"

# Single field
prompt_complexity_analyzer --only score -p "your prompt"
prompt_complexity_analyzer --only tier -p "your prompt"
prompt_complexity_analyzer --only model -p "your prompt"
prompt_complexity_analyzer --only reasoning -p "your prompt"

# Provider
prompt_complexity_analyzer --provider openai -p "your prompt"

# JSON output
prompt_complexity_analyzer --json -p "your prompt"

# Stdin
echo "your prompt" | prompt_complexity_analyzer

Load a custom ML model

from prompt_complexity_analyzer import set_model, complexity

set_model("./my_model.joblib")   # call once at startup
r = complexity("your prompt")
print(r.backend)  # ml

# Or per-call
r = complexity("your prompt", model_path="./my_model.joblib")

Semantic embeddings

The package uses sentence-transformers (all-MiniLM-L6-v2) for higher-accuracy scoring. The embedding model loads automatically on import if sentence-transformers is installed (it is — it's a hard dependency). The first run downloads ~80MB, cached locally after that.

from prompt_complexity_analyzer import load_embedding_model, complexity

load_embedding_model()   # explicit load — optional, auto-loads on import
r = complexity("your prompt")

Feature dimensions

Dimension What it measures
Vocabulary Technical word length (binned)
Multi-part Subtask signals — "also", "furthermore", numbered steps
Reasoning Depth Keywords: analyze, prove, deduce, evaluate, compare…
Domain Specificity Math · Code · Security · Medical · Legal · Finance · Science
Ambiguity Vague qualifiers: "something", "maybe", "kind of"…
Output Complexity Structured output signals: JSON, essay, table, code block

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

prompt_complexity_analyzer-0.1.1.tar.gz (270.2 kB view details)

Uploaded Source

Built Distribution

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

prompt_complexity_analyzer-0.1.1-py3-none-any.whl (275.6 kB view details)

Uploaded Python 3

File details

Details for the file prompt_complexity_analyzer-0.1.1.tar.gz.

File metadata

File hashes

Hashes for prompt_complexity_analyzer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 df35f1c8c23c24767f74e4d4baccb79634bb2fa72daa1ac4fdeb6a84d80d58b2
MD5 09105b64bf012b59f2733acdc4354959
BLAKE2b-256 079c56343c0692a63bc592646ef779540030f82cb8a6c6bb21e239feee96b206

See more details on using hashes here.

File details

Details for the file prompt_complexity_analyzer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_complexity_analyzer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23af0750c702b6abf231a2431fba298a5fa0b364f374789bc4a0593dccfef2b0
MD5 fc1d15a3eef5307e7a4ebce3c934a81f
BLAKE2b-256 9ba6e35b86f665a951510d1802c0fa8f174368a39eac1729252f61802957c9a1

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