CSL-Core
CSL-Core (Chimera Specification Language) brings mathematical rigor to AI agent governance.
Instead of relying on "please don't do that" prompts, CSL enforces:
🛡️ Deterministic Safety: Rules are enforced by a runtime engine, not the LLM itself.
📐 Formally Verified: Policies are compiled into Z3 constraints to mathematically prove they have no loopholes.
🔌 Model Agnostic: Works with OpenAI, Anthropic, Llama, or custom agents. Independent of training data.
⚖️ Auditable & Verifiable: Every decision generates a proof of compliance. Allows third-party auditing of AI behavior without exposing model weights or proprietary data.
⚠️ Alpha (0.2.x). Interfaces may change. Use in production only with thorough testing.
🚀 Quick Start (60 Seconds)
Write Your First Policy
Create my_policy.csl:
Test It (No Code Required!)
CSL-Core provides a powerful CLI for testing policies without writing any Python code:
Use in Code (Python)
📖 Table of Contents
💡 Why CSL-Core?
Scenario: You're building a LangChain or any AI agent for a fintech app. The agent can transfer funds, query databases, and send emails. You want to ensure:
❌ Junior users cannot transfer more than $1,000
❌ PII cannot be sent to external email domains
❌ The
secretstable cannot be queried by anyone
Traditional Approach (Prompt Engineering):
Problems:
⚠️ LLM can be prompt-injected ("Ignore previous instructions...")
⚠️ Rules are probabilistic (99% compliance ≠ 100%)
⚠️ No auditability (which rule was violated?)
⚠️ Fragile (adding a rule might break existing behavior)
CSL-Core Approach:
1. Define policy (my_policy.csl)
2. Load and enforce (3 lines)
3. Sleep well
Mathematically proven consistent (Z3)
LLM cannot bypass (enforcement is external)
Every violation logged with constraint name
🎯 The Problem
Modern AI is inherently probabilistic. While this enables creativity, it makes systems fundamentally unreliable for critical constraints:
❌ Prompts are suggestions, not rules
❌ Fine-tuning biases behavior but guarantees nothing
❌ Post-hoc classifiers add another probabilistic layer (more AI watching AI)
CSL-Core flips this model: Instead of asking AI to behave, you force it to comply using an external, deterministic logic layer.
✨ Key Features
🔒 Formal Verification (Z3)
Policies are mathematically proven consistent at compile-time. Contradictions, unreachable rules, and logic errors are caught before deployment.
⚡ Low-Latency Runtime
Compiled policies execute as lightweight Python functors. No heavy parsing, no API calls — just pure deterministic evaluation.
🔌 LangChain-First Integration
Drop-in protection for LangChain agents with 3 lines of code:
Context Injection: Pass runtime context (user roles, environment) that the LLM cannot override
Optional via tool_field: Tool names auto-injected into policy evaluation
Custom Context Mappers: Map complex LangChain inputs to policy variables
Zero Boilerplate: Wrap tools, chains, or entire agents with a single function call
🏭 Factory Pattern for Convenience
One-line policy loading with automatic compilation and verification:
🛡️ Fail-Closed by Design
If something goes wrong (missing data, type mismatch, evaluation error), the system blocks by default. Safety over convenience.
🔌 Drop-in Integrations
Native support for:
LangChain (Tools, Runnables, LCEL chains)
Python Functions (any callable)
REST APIs (via plugins)
📊 Built-in Observability
Every decision produces an audit trail with:
Triggered rules
Violations (if any)
Latency metrics
Optional Rich terminal visualization
🧪 Production Tests
✅ Smoke tests (parser, compiler)
✅ Logic verification (Z3 engine integrity)
✅ Runtime decisions (allow vs block)
✅ Framework integrations (LangChain)
✅ CLI end-to-end tests
✅ Real-world example policies with full test coverage
Run the entire test suite:
🚀 Quick Start (60 Seconds)
Installation
Your First Policy
Create my_policy.csl:
Test It (No Code Required!)
CSL-Core provides a powerful CLI for testing policies without writing any Python code:
Use in Code (Python)
Use in Code (LangChain)
What happens under the hood:
Every tool call is intercepted before execution
Policy is evaluated with injected context + tool inputs
Violations block execution with detailed error messages
Allowed actions pass through with zero overhead
📚 Learning Path
CSL-Core provides a structured learning journey from beginner to production:
🟢 Step 1: Quickstart (5 minutes) → quickstart/
No-code exploration of CSL basics:
What's included:
01_hello_world.csl- Simplest possible policy (1 rule)02_age_verification.csl- Multi-rule logic with numeric comparisons03_langchain_template.py- Copy-paste LangChain integration
Goal: Understand CSL syntax and CLI workflow in 5 minutes.
🟡 Step 2: Real-World Examples (30 minutes) → examples/
Use-ready policies with comprehensive test coverage:
Available Examples:
Example | Domain | Complexity | Key Features |
AI Safety | ⭐⭐ | RBAC, PII protection, tool permissions | |
Finance | ⭐⭐⭐ | Risk scoring, VIP tiers, sanctions | |
Web3 Governance | ⭐⭐⭐⭐ | Multi-sig, timelocks, emergency bypass |
Interactive Demos:
Goal: Explore production patterns and run comprehensive test suites.
🔵 Step 3: Production Deployment
Once you understand the patterns, integrate into your application:
Write your policy (or adapt from examples)
Test thoroughly using CLI batch simulation
Integrate with 3-line LangChain wrapper
Deploy with CI/CD verification (policy as code)
See Getting Started Guide for detailed walkthrough.
🏗️ Architecture: The 3-Stage Pipeline
CSL-Core separates Policy Definition from Runtime Enforcement through a clean 3-stage architecture:
Key Insight: Heavy computation (parsing, Z3 verification) happens once at compile-time. Runtime is pure evaluation — no symbolic solver, no heavy libraries.
📚 Documentation
Document | Description |
Installation, first policy, integration guide | |
Complete CSL language reference | |
Command-line tools ( | |
Design principles and vision | |
Deep dive into the problem & solution |
🎓 Example Policies Deep Dive
The examples/ directory contains policies with comprehensive test suites. Each example demonstrates real-world patterns and includes:
✅ Complete
.cslpolicy file✅ JSON test cases (allow + block scenarios)
✅ Automated test runner with visual reports
✅ Expected violations for each blocked case
Running Examples
Run all examples with the test runner:
Run specific example:
Show detailed failures:
Policy Pattern Library
Common patterns extracted from examples for reuse:
Pattern 1: Role-Based Access Control (RBAC)
Source: agent_tool_guard.csl (lines 30-33)
Pattern 2: PII Protection
Source: agent_tool_guard.csl (lines 55-58)
Pattern 3: Progressive Limits by Tier
Source: chimera_banking_case_study.csl (lines 28-38)
Pattern 4: Hard Sanctions (Fail-Closed)
Source: chimera_banking_case_study.csl (lines 22-25)
Pattern 5: Emergency Bypass
Source: dao_treasury_guard.csl (lines 60-67)
See examples/README.md for the complete policy catalog.
🧪 Testing
CSL-Core includes a comprehensive test suite following the Testing Pyramid:
Test Coverage:
✅ Smoke tests (parser, compiler)
✅ Logic verification (Z3 engine integrity)
✅ Runtime decisions (allow vs block scenarios)
✅ LangChain integration (tool wrapping, LCEL gates)
✅ CLI end-to-end (subprocess simulation)
See tests/README.md for detailed test architecture.
🔗 LangChain Integration Deep Dive
CSL-Core provides the easiest way to add deterministic safety to LangChain agents. No prompting required, no fine-tuning needed — just wrap and run.
Why LangChain + CSL-Core?
Problem | LangChain Alone | With CSL-Core |
Prompt Injection | LLM can be tricked to bypass rules | Policy enforcement happens before tool execution |
Role-Based Access | Must trust LLM to respect roles | Roles injected at runtime, LLM cannot override |
Business Logic | Encoded in fragile prompts | Mathematically verified constraints |
Auditability | Parse LLM outputs after the fact | Every decision logged with violations |
Basic Tool Wrapping
Advanced: Context Injection
The inject parameter lets you pass runtime context that the LLM cannot override:
Policy Example (agent_policy.csl):
Advanced: Custom Context Mapping
Map complex LangChain inputs to your policy variables:
Advanced: LCEL Chain Protection
Insert a policy gate into LCEL chains:
Live Demo
See a complete working example in examples/integrations/langchain_agent_demo.py:
Simulated financial agent with transfer tools
Role-based access control (USER vs ADMIN)
PII protection rules
Rich terminal visualization
🔌 Plugin Architecture
CSL-Core provides a universal plugin system for integrating with AI frameworks.
Available Plugins:
✅ LangChain (
chimera_core.plugins.langchain)🚧 LlamaIndex (coming soon)
🚧 AutoGen (coming soon)
Create Your Own Plugin:
All lifecycle behavior (fail-closed semantics, visualization, context mapping) is inherited automatically from ChimeraPlugin.
See chimera_core/plugins/README.md for the integration guide.
📖 API Quick Reference
Loading Policies (Factory Pattern)
Runtime Verification
LangChain Integration
Runtime Configuration
🛠️ CLI Tools — The Power of No-Code Policy Development
CSL-Core's CLI is not just a utility — it's a complete development environment for policies. Test, debug, and deploy without writing a single line of Python.
Why CLI-First?
⚡ Instant Feedback: Test policy changes in milliseconds
🔍 Interactive Debugging: REPL for exploring edge cases
🤖 CI/CD Ready: Integrate verification into your pipeline
📊 Batch Testing: Run hundreds of test cases with visual reports
🎨 Rich Visualization: See exactly which rules triggered
1. verify — Compile & Formally Verify
The verify command is your first line of defense. It checks syntax, semantics, and mathematical consistency using Z3.
Advanced Debugging:
Skip verification (not recommended for production):
2. simulate — Test Without Writing Code
The simulate command is your policy test harness. Pass inputs, see decisions, validate behavior.
Single Input Testing:
Batch Testing with JSON Files:
Create test_cases.json:
Run all tests:
Machine-Readable Output (CI/CD):
Runtime Behavior Flags:
3. repl — Interactive Policy Development
The REPL (Read-Eval-Print Loop) is the fastest way to explore policy behavior. Load a policy once, then test dozens of scenarios interactively.
Interactive Session:
Use Cases:
🧪 Rapid Prototyping: Test edge cases without reloading
🐛 Debugging: Explore why a specific input is blocked
📚 Learning: Understand policy behavior interactively
🎓 Demos: Show stakeholders real-time policy decisions
CLI in CI/CD Pipelines
Example: GitHub Actions
Exit Codes for Automation:
Code | Meaning | Use Case |
| Success / Allowed | Policy valid or input allowed |
| Compilation Failed | Syntax error or Z3 contradiction |
| System Error | Internal error or missing file |
| Runtime Blocked | Policy violation detected |
Advanced CLI Usage
Debug Z3 Solver Issues:
Skip Validation Steps:
Custom Runtime Behavior:
See CLI Reference for complete documentation.
🔌 MCP Server (Claude Desktop / Cursor / VS Code)
CSL-Core includes a built-in Model Context Protocol server. Write, verify, and enforce safety policies directly from your AI assistant — no code required.
Setup
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
Restart Claude Desktop. The 🔌 icon confirms the connection.
Available Tools
Tool | What It Does |
| Z3 formal verification — catches contradictions at compile time |
| Test policies against JSON inputs — returns ALLOWED/BLOCKED |
| Human-readable summary of any CSL policy |
| Generate a CSL template from plain-English description |
Example Conversation
You: "Write me a safety policy that prevents my AI agent from making transfers over $5000 without admin approval"
Claude: uses scaffold_policy → you edit → verify_policy catches a contradiction → you fix → simulate_policy confirms it works
Install with MCP support
🎯 Use Cases
CSL-Core is ready for:
🏦 Financial Services
Transaction limits by user tier
Sanctions enforcement
Risk-based blocking
Fraud prevention rules
🤖 AI Agent Safety
Tool permission management
PII protection
Rate limiting
Dangerous operation blocking
🏛️ DAO Governance
Multi-sig requirements
Timelock enforcement
Reputation-based access
Treasury protection
🏥 Healthcare
HIPAA compliance rules
Patient data access control
Treatment protocol validation
Audit trail requirements
⚖️ Legal & Compliance
Regulatory rule enforcement
Contract validation
Policy adherence verification
Automated compliance checks
** CSL-Core is currently in Alpha, provided 'as-is' without any warranties; the developers accept no liability for any direct or indirect damages resulting from its use. **
🗺️ Roadmap
✅ Completed
Core language (CSL syntax, parser, AST)
Z3 formal verification engine
Python runtime with fail-closed semantics
LangChain integration (Tools, LCEL, Runnables)
Factory pattern for easy policy loading
CLI tools (verify, simulate, repl)
Rich terminal visualization
Comprehensive test suite
Custom context mappers for framework integration
MCP Server (Claude Desktop, Cursor, VS Code integration)
🚧 In Progress
Policy versioning & migration tools
Web-based policy editor
LangGraph integration
🔮 Planned
LlamaIndex integration
AutoGen integration
Haystack integration
Policy marketplace (community-contributed policies)
Cloud deployment templates (AWS Lambda, GCP Functions, Azure Functions)
Policy analytics dashboard
Multi-policy composition
Hot-reload support for development
🔒 Enterprise (Commercial)
TLA+ temporal logic verification
Causal inference engine
Multi-tenancy support
Advanced policy migration tooling
Priority support & SLA
🤝 Contributing
We welcome contributions! CSL-Core is open-source and community-driven.
Ways to Contribute:
🐛 Report bugs via GitHub Issues
💡 Suggest features or improvements
📝 Improve documentation
🧪 Add test cases
🎓 Create example policies for new domains
🔌 Build framework integrations (LlamaIndex, AutoGen, Haystack)
🌟 Share your LangChain use cases and integration patterns
High-Impact Contributions We'd Love:
📚 More real-world example policies (healthcare, legal, supply chain)
🔗 Framework integrations (see
chimera_core/plugins/base.pyfor the pattern)🎨 Web-based policy editor
📊 Policy analytics and visualization tools
🧪 Additional test coverage for edge cases
Contribution Process:
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Make your changes with tests
Run the test suite (
pytest)Commit your changes (
git commit -m 'Add amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
See CONTRIBUTING.md for detailed guidelines.
📄 License & Open-Core Model
Core (This Repository)
CSL-Core is released under the Apache License 2.0. See LICENSE for details.
What's included in the open-source core:
✅ Complete CSL language (parser, compiler, runtime)
✅ Z3-based formal verification
✅ LangChain integration
✅ CLI tools (verify, simulate, repl)
✅ Rich terminal visualization
✅ All example policies and test suites
Enterprise Edition (Optional / Under Research & Deployment)
Advanced capabilities for large-scale deployments:
🔒 TLA+ Temporal Logic Verification: Beyond Z3, full temporal model checking
🔒 Causal Inference Engine: Counterfactual analysis and causal reasoning
🔒 Multi-tenancy Support: Policy isolation and tenant-scoped enforcement
🔒 Policy Migration Tools: Version control and backward compatibility
🔒 Cloud Deployment Templates: Production-ready Kubernetes/Lambda configs
🔒 Priority Support: SLA-backed engineering support
🙏 Acknowledgments
CSL-Core is built on the shoulders of giants:
Z3 Theorem Prover - Microsoft Research (Leonardo de Moura, Nikolaj Bjørner)
LangChain - Harrison Chase and contributors
Rich - Will McGugan (terminal visualization)
📬 Contact & Support
GitHub Issues: Report bugs or request features
Discussions: Ask questions, share use cases
Email: akarlaraytu@gmail.com
⭐ Star History
If you find CSL-Core useful, please consider giving it a star on GitHub! It helps others discover the project.
Built with ❤️ by the Chimera project
Making AI systems mathematically safe, one policy at a time.