Official Python SDK for RAIL Score API - Responsible AI Content Evaluation
Project description
RAIL Score Python SDK
Official Python client library for the RAIL Score API - Evaluate AI-generated content across 8 dimensions of Responsible AI.
🎯 Features
- ✅ Comprehensive RAIL Scoring - Evaluate content across 8 dimensions
- ✅ Content Generation - Generate content with automatic RAIL checks
- ✅ Content Improvement - Regenerate and improve existing content
- ✅ Tone Analysis - Extract and match tone profiles
- ✅ Compliance Checking - GDPR, HIPAA, NIST, SOC 2 compliance
- ✅ Type-Safe - Full type hints for better IDE support
- ✅ Error Handling - Custom exceptions for different error scenarios
- ✅ Simple API - Clean, intuitive interface
📦 Installation
pip install rail-score-sdk
For development:
pip install rail-score-sdk[dev]
🚀 Quick Start
from rail_score_sdk import RailScoreClient
# Initialize client
client = RailScoreClient(
api_key='your-api-key'
# base_url is optional, defaults to https://api.responsibleailabs.ai
)
# Calculate RAIL score
result = client.calculate(
content="AI should prioritize human welfare and be transparent.",
domain='general',
explain_scores=True
)
print(f"RAIL Score: {result.rail_score}/10")
print(f"Grade: {result.grade}")
print(f"Strengths: {result.overall_analysis.strengths}")
print(f"Weaknesses: {result.overall_analysis.weaknesses}")
# View dimension scores
for dim, details in result.dimension_scores.items():
print(f"{dim}: {details.score}/10 ({details.grade})")
print(f" Suggestions: {details.suggestions}")
📚 Documentation
Calculate RAIL Score
Evaluate content across all 8 RAIL dimensions:
result = client.calculate(
content="Your content here",
domain='general', # Options: general, healthcare, law, hr, politics, news, finance
explain_scores=True,
source='chatgpt', # Optional: chatgpt, gemini, claude, grok, custom, pasted
custom_weights={ # Optional: custom dimension weights
'fairness': 0.15,
'safety': 0.20,
'reliability': 0.15,
# ... must sum to 1.0
}
)
print(f"Score: {result.rail_score}/10 ({result.grade})")
Generate Content
Generate content with automatic RAIL quality checks:
result = client.generate(
prompt="Write about AI ethics in healthcare",
length='medium', # Options: short, medium, long
context={
'purpose': 'blog_post',
'industry': 'healthcare',
'target_audience': 'professionals',
'tone': 'professional'
},
rail_requirements={
'minimum_scores': {
'safety': 8.0,
'reliability': 7.5
},
'auto_regenerate': True,
'max_attempts': 3
}
)
print(f"Generated Content:\n{result.content}")
print(f"RAIL Score: {result.rail_scores.rail_score}")
print(f"Attempts: {result.generation_metadata.attempts}")
Regenerate Content
Improve existing content based on feedback:
result = client.regenerate(
original_content="Original content here",
improve_dimensions=['fairness', 'safety', 'inclusivity'],
user_notes="Make it more inclusive and balanced",
keep_structure=True,
keep_tone=True
)
print(f"Improved Content:\n{result.content}")
# View improvements
for dim, improvement in result.improvements.items():
print(f"{dim}: {improvement.before} → {improvement.after} (+{improvement.improvement})")
Analyze Tone
Extract tone profile from URLs or text:
result = client.analyze_tone(
sources=[
{'type': 'url', 'value': 'https://example.com/blog'},
{'type': 'text', 'value': 'Sample text here'}
],
create_profile=True,
profile_name='Brand Voice'
)
tone = result.tone_profile.characteristics
print(f"Formality: {tone.formality}")
print(f"Complexity: {tone.complexity}")
print(f"Voice: {tone.voice}")
Match Tone
Adjust content to match a specific tone:
result = client.match_tone(
content="Content to adjust",
tone_profile_id='profile_123', # From analyze_tone
adjustment_level='moderate' # Options: subtle, moderate, strong
)
print(f"Matched Content:\n{result.matched_content}")
print(f"Match Score: {result.match_score}")
Check Compliance
Evaluate against compliance frameworks:
# GDPR Compliance
result = client.check_compliance(
content="Privacy policy text",
framework='gdpr',
context_type='privacy_policy',
check_consent=True,
check_data_minimization=True
)
print(f"Compliance Status: {result.compliance_status}")
print(f"Overall Score: {result.overall_score}")
print(f"Violations: {result.violations}")
print(f"Recommendations: {result.recommendations}")
# Other frameworks: 'nist', 'hipaa', 'soc2'
Health Check
Check API health status:
health = client.health()
print(f"Status: {health['status']}")
version = client.version()
print(f"API Version: {version['version']}")
🎯 RAIL Dimensions
The SDK evaluates content across 8 dimensions:
- Fairness - Bias detection and equitable treatment
- Safety - Toxicity and harmful content detection
- Reliability - Factual accuracy and consistency
- Transparency - Clear reasoning and source citation
- Privacy - PII detection and data protection
- Accountability - Verifiable claims and attribution
- Inclusivity - Diverse perspectives and inclusive language
- User Impact - Emotional tone and audience appropriateness
🔐 Authentication
The SDK supports two authentication methods:
API Key (Recommended)
client = RailScoreClient(api_key='your-rail-api-key')
JWT Token
from rail_score_sdk import RailScoreClients
client = RailScoreClient(api_key='your-rail-api-key')
# JWT token is automatically added to requests
🛡️ Error Handling
The SDK provides custom exceptions for different error scenarios:
from rail_score_sdk import (
RailScoreError,
AuthenticationError,
RateLimitError,
InsufficientCreditsError,
ValidationError,
)
try:
result = client.calculate(content="...")
except AuthenticationError:
print("Authentication failed - check your RAIL API key")
except RateLimitError:
print("Rate limit exceeded - wait before retrying")
except InsufficientCreditsError:
print("Out of credits - upgrade your plan")
except ValidationError as e:
print(f"Validation error: {e.message}")
except RailScoreError as e:
print(f"RAIL API error: {e.message}")
⚙️ Configuration
Environment Variables
import os
from rail_score_sdk import RailScoreClient
client = RailScoreClient(
api_key=os.getenv('RAIL_API_KEY'),
base_url=os.getenv('RAIL_BASE_URL', 'https://api.responsibleailabs.ai'),
timeout=int(os.getenv('RAIL_TIMEOUT', '30'))
)
Timeouts
# Set custom timeout (in seconds)
client = RailScoreClient(
api_key='your-api-key',
timeout=60 # 60 seconds
)
💳 Plans & Credits
| Plan | Monthly Credits | Auto-Renewal | Price (Monthly) | Price (Yearly/month) |
|---|---|---|---|---|
| Free | 100 | Every 30 days | Free | Free |
| Pro | 1,000 | Every 30 days | ₹2,399 / $29 | ₹1,999 / $23 |
| Business | 10,000 | Every 30 days | ₹21,999 / $247 | ₹18,999 / $214 |
| Enterprise | 50,000 | Every 30 days | Contact Sales | Contact Sales |
Credit Expiry:
- Monthly tier credits expire in 30 days
- Purchased topup credits never expire
- Get your API key at: https://responsibleailabs.ai/dashboard
📊 Rate Limits
| Endpoint Type | Rate Limit |
|---|---|
| API Endpoints | 60 requests / minute |
| Auth Endpoints | 5 requests / 15 minutes |
Note: Rate limits apply per API key, regardless of plan tier.
🧪 Testing
# Install dev dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
# Run with coverage
pytest --cov=rail_score_sdk --cov-report=html
# Format code
black rail_score_sdk/
# Type checking
mypy rail_score_sdk/
📖 Examples
See the examples directory for comprehensive usage examples:
Beginner:
basic_usage.py- Basic RAIL scoring and evaluationcontent_generation.py- Generate content with RAIL checkstone_matching.py- Tone analysis and brand voice matching
Intermediate:
regenerate_content.py- Improve and refine existing contentcompliance_check.py- GDPR, HIPAA, NIST, SOC2 compliancebatch_processing.py- Process multiple texts efficiently
Advanced:
error_handling.py- Production-ready error handlingadvanced_features.py- Custom weights, workflows, and analyticsenvironment_config.py- Multi-environment deployment setup
See examples/README.md for detailed documentation.
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide first.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
- Documentation: https://responsibleailabs.ai/developer/docs
- API Reference: https://responsibleailabs.ai/developers/api-ref
- GitHub: https://github.com/RAILethicsHub/sdks/python/
- PyPI: https://pypi.org/project/rail-score-sdk/
- Support: research@responsibleailabs.ai
📞 Support
- 📧 Email: research@responsibleailabs.ai
- 💬 Discord: Join our community
- 📖 Documentation: https://responsibleailabs.ai/developer/docs
- 🐛 Issues: https://github.com/RAILethicsHub/sdks/python/issues
Project details
Release history Release notifications | RSS feed
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 rail_score_sdk-1.0.1.tar.gz.
File metadata
- Download URL: rail_score_sdk-1.0.1.tar.gz
- Upload date:
- Size: 36.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d4da30bafb17fe357a34fac5807be8163fc2c297e9272a9fa0dfa46e45aa9b3
|
|
| MD5 |
b5f93388547744167ffff6f4630f4e4c
|
|
| BLAKE2b-256 |
6351db0d5d6661d48edd0e8c24beaf31ed435e857fdc339e08abd5c580ac98a5
|
File details
Details for the file rail_score_sdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: rail_score_sdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80938fdcac5d77633f0c448b58bfd691fd785333df8b094eca638242ce4d639b
|
|
| MD5 |
a182d084ac162c5c64b566a0ef2910ad
|
|
| BLAKE2b-256 |
651ea83f1f739149d11da3c868cd778d7eec3fd7d4726c721c3c6534af185e54
|