CSL-Core
CSL-Core
❤️ コントリビューターの皆様!
CSL-Core (Chimera Specification Language) は、AIエージェントのための決定論的な安全レイヤーです。.cslファイルでルールを記述し、Z3で数学的に検証し、モデルの外部で実行時に強制します。LLMはルールを認識しません。ルールに違反することは不可能です。
pip install csl-core元々はProject Chimeraのために構築されましたが、現在はあらゆるAIシステム向けにオープンソース化されています。
なぜ必要なのか?
prompt = """You are a helpful assistant. IMPORTANT RULES:
- Never transfer more than $1000 for junior users
- Never send PII to external emails
- Never query the secrets table"""プロンプトによる安全対策は機能しません。LLMはプロンプトインジェクションを受ける可能性があり、ルールは確率的(99% ≠ 100%)であり、問題が発生した際の監査証跡もありません。
CSL-Coreはこれを覆します:ルールはモデルの外部にあるコンパイル済みのZ3検証済みポリシーファイルに存在します。強制は決定論的であり、単なる提案ではありません。
クイックスタート (60秒)
1. ポリシーの記述
my_policy.cslを作成します:
CONFIG {
ENFORCEMENT_MODE: BLOCK
CHECK_LOGICAL_CONSISTENCY: TRUE
}
DOMAIN MyGuard {
VARIABLES {
action: {"READ", "WRITE", "DELETE"}
user_level: 0..5
}
STATE_CONSTRAINT strict_delete {
WHEN action == "DELETE"
THEN user_level >= 4
}
}2. 検証とテスト (CLI)
# Compile + Z3 formal verification
cslcore verify my_policy.csl
# Test a scenario
cslcore simulate my_policy.csl --input '{"action": "DELETE", "user_level": 2}'
# → BLOCKED: Constraint 'strict_delete' violated.
# Interactive REPL
cslcore repl my_policy.csl3. Pythonでの利用
from chimera_core import load_guard
guard = load_guard("my_policy.csl")
result = guard.verify({"action": "READ", "user_level": 1})
print(result.allowed) # True
result = guard.verify({"action": "DELETE", "user_level": 2})
print(result.allowed) # Falseベンチマーク:敵対的攻撃への耐性
プロンプトベースの安全ルールとCSL-Coreによる強制を、4つの最先端LLM、22の敵対的攻撃、15の正当な操作でテストしました:
アプローチ | ブロックされた攻撃 | バイパス率 | 通過した正当な操作 | レイテンシ |
GPT-4.1 (プロンプトルール) | 10/22 (45%) | 55% | 15/15 (100%) | ~850ms |
GPT-4o (プロンプトルール) | 15/22 (68%) | 32% | 15/15 (100%) | ~620ms |
Claude Sonnet 4 (プロンプトルール) | 19/22 (86%) | 14% | 15/15 (100%) | ~480ms |
Gemini 2.0 Flash (プロンプトルール) | 11/22 (50%) | 50% | 15/15 (100%) | ~410ms |
CSL-Core (決定論的) | 22/22 (100%) | 0% | 15/15 (100%) | ~0.84ms |
なぜ100%なのか? 強制はモデルの外部で行われるためです。プロンプトインジェクションの対象が存在しないため、無効化されます。攻撃カテゴリ:直接的な命令の上書き、ロールプレイによる脱獄、エンコーディングのトリック、マルチターンでのエスカレーション、ツール名のなりすましなど。
完全な手法:
benchmarks/
LangChain統合
プロンプトの変更やファインチューニングなしで、3行のコードでLangChainエージェントを保護します:
from chimera_core import load_guard
from chimera_core.plugins.langchain import guard_tools
from langchain_classic.agents import AgentExecutor, create_tool_calling_agent
guard = load_guard("agent_policy.csl")
# Wrap tools — enforcement is automatic
safe_tools = guard_tools(
tools=[search_tool, transfer_tool, delete_tool],
guard=guard,
inject={"user_role": "JUNIOR", "environment": "prod"}, # LLM can't override these
tool_field="tool" # Auto-inject tool name
)
agent = create_tool_calling_agent(llm, safe_tools, prompt)
executor = AgentExecutor(agent=agent, tools=safe_tools)すべてのツール呼び出しは実行前にインターセプトされます。ポリシーが拒否すれば、ツールは実行されません。以上。
コンテキストインジェクション
LLMが上書きできないランタイムコンテキスト(ユーザーロール、環境、レート制限など)を渡します:
safe_tools = guard_tools(
tools=tools,
guard=guard,
inject={
"user_role": current_user.role, # From your auth system
"environment": os.getenv("ENV"), # prod/dev/staging
"rate_limit_remaining": quota.remaining # Dynamic limits
}
)LCELチェーンの保護
from chimera_core.plugins.langchain import gate
chain = (
{"query": RunnablePassthrough()}
| gate(guard, inject={"user_role": "USER"}) # Policy checkpoint
| prompt | llm | StrOutputParser()
)CLIツール
CLIは、Pythonを書かずにポリシーのテスト、デバッグ、デプロイを行うための完全な開発環境です。
verify — コンパイル + Z3証明
cslcore verify my_policy.csl
# ⚙️ Compiling Domain: MyGuard
# • Validating Syntax... ✅ OK
# ├── Verifying Logic Model (Z3 Engine)... ✅ Mathematically Consistent
# • Generating IR... ✅ OKsimulate — シナリオテスト
# Single input
cslcore simulate policy.csl --input '{"action": "DELETE", "user_level": 2}'
# Batch testing from file
cslcore simulate policy.csl --input-file test_cases.json --dashboard
# CI/CD: JSON output
cslcore simulate policy.csl --input-file tests.json --json --quietrepl — インタラクティブ開発
cslcore repl my_policy.csl --dashboard
cslcore> {"action": "DELETE", "user_level": 2}
🛡️ BLOCKED: Constraint 'strict_delete' violated.
cslcore> {"action": "DELETE", "user_level": 5}
✅ ALLOWEDformal — TLA⁺モデル検査
cslcore formal my_policy.csl公式のTLCモデルチェッカー (java -jar tla2tools.jar) をポリシーに対して実行します。TLCは抽象状態空間内のすべての到達可能な状態を網羅的に探索し、各時間的特性が保持されていることを証明します。保持されていない場合は、不変条件を破る正確な状態を示す具体的な反例トレースを返します。
╔══════════════════════════════════════════════════════════════════════════════╗
║ TLA⁺ FORMAL VERIFICATION ENGINE ║
║ Chimera Specification Language · Temporal Logic of Actions ║
║ ║
║ ⚡ REAL TLC · java -jar tla2tools.jar · Exhaustive Model Checking ║
║ TLC2 Version 2026.03.31.154134 (rev: becec35) · pid 48146 · 1 ║
║ worker(s) ║
╚══════════════════════════════════════════════════════════════════════════════╝
Variable Domain Cardinality
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
agent_tier {"STANDARD", "PREMIUM"} |2|
task_type {"READ", "WRITE", "ANALYZE"} |3|
risk_score 0..5 |6|
├─ □(no_destructive_ops) ✅ HOLDS [288 states 349ms]
├─ □(no_production_access) ✅ HOLDS [288 states 349ms]
├─ □(bounded_risk) ✅ HOLDS [288 states 349ms]
└─ Proof hash: 17dd1564897d242fc045a3a884a52bbb… ✅
╔══════════════ TLA⁺ VERIFICATION COMPLETE — ALL PROPERTIES HOLD ══════════════╗
║ ✅ Domain: AIAgentSafetyDemo · ⬡ 144 states · ⏱ 1047ms ║
╚══════════════════════════════════════════════════════════════════════════════╝CONFIGに1行追加することで有効化します:
CONFIG {
ENFORCEMENT_MODE: BLOCK
ENABLE_FORMAL_VERIFICATION: TRUE // ← triggers cslcore formal automatically
}またはスタンドアロンで実行します:
cslcore formal policy.csl # real TLC (Java required, JAR auto-downloaded)
cslcore formal policy.csl --mock # Python BFS fallback (no Java needed)
cslcore formal policy.csl --timeout 120
cslcore formal policy.csl --export-tla ./specs/ # save .tla + .cfg for TLA+ ToolboxJavaがない場合? CSL-Coreは自動的にPythonのBFSモデルチェッカーにフォールバックします。バナーにはどのエンジンが実行されたかが明確に表示されます。JARは初回使用時に自動的にダウンロードされます(公式TLA+ GitHubリリースから約4MB)。
CI/CDパイプライン
# GitHub Actions
- name: Verify policies
run: |
for policy in policies/*.csl; do
cslcore verify "$policy" || exit 1
doneMCPサーバー (Claude Desktop / Cursor / VS Code)
AIアシスタントから直接安全ポリシーを記述、検証、強制します。コードは不要です。
pip install "csl-core[mcp]"Claude Desktopの設定 (~/Library/Application Support/Claude/claude_desktop_config.json) に追加します:
{
"mcpServers": {
"csl-core": {
"command": "uv",
"args": ["run", "--with", "csl-core[mcp]", "csl-core-mcp"]
}
}
}ツール | 機能 |
| Z3形式検証 — コンパイル時に矛盾を検出 |
| JSON入力に対するポリシーのテスト — 許可/ブロック |
| CSLポリシーの人間が読める要約 |
| 平易な英語の説明からCSLテンプレートを生成 |
あなた: "管理者の承認なしに5000ドルを超える送金を防ぐ安全ポリシーを書いて"
Claude: scaffold_policy → あなたが編集 → verify_policyが矛盾を検出 → あなたが修正 → simulate_policyが動作を確認
アーキテクチャ
┌──────────────────────────────────────────────────────────┐
│ 1. COMPILER .csl → AST → IR → Compiled Artifact │
│ Syntax validation, semantic checks, functor gen │
├──────────────────────────────────────────────────────────┤
│ 2. Z3 VERIFIER Theorem Prover — Static Analysis │
│ Contradiction detection, reachability, rule shadowing │
│ ⚠️ If verification fails → policy will NOT compile │
├──────────────────────────────────────────────────────────┤
│ 3. TLA⁺ VERIFIER Model Checker — Temporal Safety │
│ Exhaustive state-space exploration via TLC │
│ Predicate abstraction for large numeric domains │
│ Counterexample traces + automated fix suggestions │
│ (opt-in: ENABLE_FORMAL_VERIFICATION: TRUE) │
├──────────────────────────────────────────────────────────┤
│ 4. RUNTIME Deterministic Policy Enforcement │
│ Fail-closed, zero dependencies, <1ms latency │
└──────────────────────────────────────────────────────────┘重い計算はコンパイル時に一度だけ行われます。ランタイムは純粋な評価のみです。
本番環境での利用
CSL-Coreをご利用ですか?お知らせいただければこちらに追加いたします。
ポリシー例
例 | ドメイン | 主な機能 |
AIの安全性 | RBAC、PII保護、ツール権限 | |
金融 | リスクスコアリング、VIP階層、制裁 | |
Web3 | マルチシグ、タイムロック、緊急バイパス | |
形式手法 | TLA⁺モデル検査 — すべての特性が保持される | |
形式手法 | TLA⁺反例トレース + 修正案 |
python examples/run_examples.py # Run all with test suites
python examples/run_examples.py banking # Run specific exampleAPIリファレンス
from chimera_core import load_guard, RuntimeConfig
# Load + compile + verify
guard = load_guard("policy.csl")
# With custom config
guard = load_guard("policy.csl", config=RuntimeConfig(
raise_on_block=False, # Return result instead of raising
collect_all_violations=True, # Report all violations, not just first
missing_key_behavior="block" # "block", "warn", or "ignore"
))
# Verify
result = guard.verify({"action": "DELETE", "user_level": 2})
print(result.allowed) # False
print(result.violations) # ['strict_delete']完全なドキュメント: Getting Started · Syntax Spec · CLI Reference · Philosophy
ロードマップ
✅ 完了: コア言語とパーサー · Z3検証 · フェイルクローズドなランタイム · LangChain統合 · CLI (verify, simulate, repl, formal) · MCPサーバー · 公式TLCによるTLA⁺モデル検査 · 述語抽象化 · 反例分析 · Chimera v1.7.0での本番デプロイ
🚧 進行中: ポリシーのバージョン管理 · LangGraph統合
🔮 計画中: LlamaIndex & AutoGen · ポリシーの合成 · ホットリロード · ポリシーマーケットプレイス · クラウドテンプレート
🔒 エンタープライズ (研究中): 因果推論 · マルチテナンシー
コントリビューション
コントリビューションを歓迎します!good first issueから始めるか、CONTRIBUTING.mdを確認してください。
影響力の大きい分野: 実世界のポリシー例 · フレームワーク統合 · Webベースのポリシーエディタ · テストカバレッジ
ライセンス
Apache 2.0 (オープンコアモデル)。言語全体、コンパイラ、Z3検証ツール、ランタイム、CLI、MCPサーバー、およびすべての例はオープンソースです。LICENSEを参照してください。
Built with ❤️ by Chimera Protocol · Issues · Discussions · Email
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Chimera-Protocol/csl-core'
If you have feedback or need assistance with the MCP directory API, please join our Discord server