Open-source Python toolkit to inspect, test, secure, optimize, and operationalize GenAI applications before production.
Project description
GenAIScope
Inspect, test, secure, optimize, and operationalize GenAI applications before production.
GenAIScope is a production-quality Python library that helps developers, CTOs, and AI engineers identify and fix issues in GenAI applications. It provides lightweight, powerful tooling for detecting gaps in prompts, RAG quality, hallucination risks, structured output failures, unsafe agent tools, PII leakage, cost inefficiency, weak testing, missing observability, and poor production readiness.
Key Features
- One-line APIs for beginners - Easy to use for quick checks
- Deep inspection APIs - Advanced capabilities for engineering teams
- CLI-first experience - Interact via command line or Python
- Local-first - Run everything locally by default
- Modular design - Mix and match what you need
- Production-ready - Type-safe, async-capable, fully tested
What Makes GenAIScope Different
- Not another LLM framework (like LangChain)
- Not just another observability platform (like Langfuse)
- Not only an eval framework (like Ragas or DeepEval)
- Not just an LLM gateway (like Helicone)
GenAIScope is a readiness and manipulation toolkit - lightweight but comprehensive - designed to help teams operationalize GenAI applications safely and efficiently.
Installation
pip install genaiscope
Optional Dependencies
# For OpenAI support
pip install genaiscope[openai]
# For Anthropic support
pip install genaiscope[anthropic]
# For Google Gemini support
pip install genaiscope[google]
# For development
pip install genaiscope[dev]
# For documentation building
pip install genaiscope[docs]
# Everything
pip install genaiscope[all]
Quick Start
Python API
from genaiscope import Inspector
# Create an inspector
inspector = Inspector()
# Inspect a prompt
report = inspector.inspect_prompt("What is the capital of France?")
print(report.summary())
# Inspect RAG output
rag_report = inspector.inspect_rag(
query="What is AI?",
context="Artificial Intelligence is...",
response="AI is..."
)
print(rag_report.summary())
# Inspect structured output
output_report = inspector.inspect_output(
'{"name": "test"}',
expected_format="json"
)
print(output_report.summary())
CLI Usage
# Show version
genaiscope version
# Show configuration
genaiscope config-show
# Inspect a prompt
genaiscope inspect-prompt "What is AI?"
# Detect PII in text
genaiscope detect-pii "My email is john@example.com"
# Redact PII
genaiscope detect-pii "Email: john@example.com" --redact
# Estimate API costs
genaiscope estimate-cost gpt-4 100 200
# Analyze text for issues
genaiscope analyze-text "Your text here" --analyze-pii --analyze-hallucination --context "background"
# Validate output format
genaiscope validate-output '{"test": "data"}' --format json
Core Modules
Inspector
The main entry point for inspecting GenAI applications:
from genaiscope import Inspector
inspector = Inspector()
# Prompt inspection
report = inspector.inspect_prompt(prompt)
# RAG inspection
report = inspector.inspect_rag(query, context, response)
# Output inspection
report = inspector.inspect_output(output, expected_format="json")
Analyzers
Specialized analyzers for different types of issues:
from genaiscope.analyzers import (
CostAnalyzer,
PIIDetector,
HallucinationDetector,
SafetyAnalyzer,
StructuredOutputValidator,
)
# Cost analysis
cost_analyzer = CostAnalyzer()
costs = cost_analyzer.estimate_cost("gpt-4", input_tokens, output_tokens)
# PII detection
pii_detector = PIIDetector()
detections = pii_detector.detect(text)
redacted = pii_detector.redact(text)
# Hallucination detection
detector = HallucinationDetector()
results = detector.detect(context, response)
# Safety analysis
analyzer = SafetyAnalyzer()
issues = analyzer.analyze(text)
# Structured output validation
validator = StructuredOutputValidator()
result = validator.validate_json(text)
Scoring Engine
Evaluate and score text:
from genaiscope import ScoringEngine
engine = ScoringEngine()
# Use built-in scorers
score = engine.score(text, "length")
result = engine.evaluate(text, "null_safety", threshold=0.5)
# Register custom scorers
def my_scorer(text):
return 0.8
engine.register("custom", my_scorer)
score = engine.score(text, "custom")
Configuration
Set configuration via environment variables:
# Provider settings
export GENAISCOPE_PROVIDER=openai
export OPENAI_API_KEY=sk-...
export GENAISCOPE_MODEL=gpt-4
# Execution settings
export GENAISCOPE_MAX_TOKENS=2048
export GENAISCOPE_TEMPERATURE=0.7
export GENAISCOPE_TIMEOUT=30
export GENAISCOPE_RETRIES=3
# Logging
export GENAISCOPE_LOG_LEVEL=INFO
export GENAISCOPE_LOG_FILE=genaiscope.log
Or use the Python API:
from genaiscope.core.config import set_config, Config
config = Config(
provider="openai",
openai_api_key="sk-...",
model="gpt-4",
temperature=0.7,
)
set_config(config)
Testing
Run the test suite:
pytest tests/
Run with coverage:
pytest tests/ --cov=src/genaiscope
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/genaiscope/genaiscope.git
cd genaiscope
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install in development mode with all dependencies
pip install -e ".[dev,docs]"
Run Tests
pytest tests/ -v
Run Linting
ruff check src/
black --check src/
mypy src/
Format Code
black src/ tests/
ruff check --fix src/
Build Documentation
mkdocs serve
Project Structure
genaiscope/
├── pyproject.toml # Project configuration
├── README.md # This file
├── LICENSE # MIT License
├── CHANGELOG.md # Version history
├── CONTRIBUTING.md # Contribution guidelines
├── CODE_OF_CONDUCT.md # Community guidelines
├── .gitignore # Git ignore rules
├── .env.example # Environment template
├── mkdocs.yml # Documentation config
├── docs/ # Documentation
│ ├── index.md
│ ├── quickstart.md
│ ├── installation.md
│ ├── concepts.md
│ ├── cli.md
│ ├── api-reference.md
│ ├── recipes/
│ └── comparisons/
├── src/genaiscope/ # Package source
│ ├── __init__.py
│ ├── version.py
│ ├── cli.py # CLI interface
│ ├── inspect.py # Main inspector
│ ├── analyzers.py # Specialized analyzers
│ ├── scoring.py # Scoring engine
│ └── core/ # Core modules
│ ├── config.py
│ ├── models.py
│ ├── errors.py
│ ├── providers.py
│ ├── logging.py
│ ├── result.py
│ └── core_inspect.py
└── tests/ # Test suite
├── test_models.py
├── test_analyzers.py
├── test_inspect.py
└── test_scoring.py
API Reference
Inspector
inspect_prompt(prompt: str) -> InspectionReport- Analyze prompt qualityinspect_rag(query: str, context: str, response: str) -> InspectionReport- Analyze RAG systeminspect_output(output: str, expected_format: Optional[str]) -> InspectionReport- Validate output
Analyzers
CostAnalyzer.estimate_cost(model: str, input_tokens: int, output_tokens: int)- Calculate costsPIIDetector.detect(text: str)- Detect PIIPIIDetector.redact(text: str)- Redact PIIHallucinationDetector.detect(context: str, response: str)- Detect hallucinationsSafetyAnalyzer.analyze(text: str)- Analyze for safety issuesStructuredOutputValidator.validate_json(text: str)- Validate JSON
ScoringEngine
score(text: str, scorer_name: str) -> float- Score textevaluate(text: str, scorer_name: str, threshold: float) -> EvaluationResult- Evaluate textregister(name: str, scorer: Callable)- Register custom scorer
Testing
GenAIScope includes comprehensive tests for all components. See TESTING.md for:
- ✅ Setup instructions
- ✅ Running unit tests with pytest
- ✅ Code quality checks (ruff, black, mypy)
- ✅ Coverage reports
- ✅ Manual testing procedures
- ✅ CI/CD validation with GitHub Actions
- ✅ Performance profiling
- ✅ Troubleshooting guide
Quick test command:
pip install -e ".[dev]"
pytest tests/ -v
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE for details.
Support
Roadmap
- Agent safety analysis
- Cost optimization recommendations
- CI/CD integration
- Web dashboard
- Enterprise observability
- More provider integrations
- Advanced RAG analysis
- Prompt optimization suggestions
GenAIScope: Making GenAI applications production-ready.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genaiscope-0.1.0.tar.gz.
File metadata
- Download URL: genaiscope-0.1.0.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77879536ea0039f7296d97353cd1d0cc804b0ab6a0217ecdb292a2e71c731c61
|
|
| MD5 |
5220fa317e107179faceecd983f39b73
|
|
| BLAKE2b-256 |
d9df94c21f070ec9d153729e0170dd35efc83e8a5973da43619d0c7a8f047dcd
|
File details
Details for the file genaiscope-0.1.0-py3-none-any.whl.
File metadata
- Download URL: genaiscope-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca94a1b855536213ee2250840df030d50d347f5b927ac50b163e81c543014f18
|
|
| MD5 |
952b8f896348ac5b31ae8256d73a47a1
|
|
| BLAKE2b-256 |
597f23589e59683145e9e2741b1d77b516dbc914710793f70840243e9e25d190
|