cliver-playbook-app-rag-governance
A reusable governance loop over the cliver-playbook RAG stack: one project
per knowledge-base scenario, intent rules that decide retrieval scope and
tools, a golden dataset that gates change, staged ingestion with an approval
gate, document-level access control, and a query facade that enforces both
document clearance and tool authority.
The package composes on top of cliver-playbook-app-rag and never replaces
it. Documents, chunks, embeddings and retrieval stay owned by rag; this
package adds the project-level lifecycle around them. Package chain:
cliver-playbook-app-basic <- cliver-playbook-app-user
<- cliver-playbook-app-rag <- cliver-playbook-app-rag-governance
Full design: docs/superpowers/specs/2026-11-05-rag-governance-loop-design.md
(local-only) and ADR-0023.
What is inside
| Area | Module | Responsibility |
|---|---|---|
| Projects | services/projects.py, api/projects.py |
Project row and versioned configuration: scope strategy, retrieval knobs, embedder, thresholds, approval mode. |
| Sources and batches | services/sources.py, services/batches.py, api/sources.py, api/batches.py |
Source definitions, ingestion batches, staged rows and the publish transition. |
| Ingestion | ingestion/ |
Masking, parent/child splitting, contextual prefixes, embedding and staging. |
| Golden sets | golden/, api/golden.py |
Candidate generation, JSONL codec, immutable confirmed versions, per-case edits. |
| Intent rules | rules/, api/rules.py |
Priority-ordered keyword/regex rules, typed filter-AST scopes, none/retrieval/tools/agentic strategies. |
| Evaluation | evaluation/, api/evaluations.py |
Runner, evaluators, hard gates, thresholds, case-level and aggregate reports. |
| Approvals | services/approvals.py, api/approvals.py |
Approve/reject a staged batch, audit, publish or discard. |
| Jobs | runtime/jobs.py |
DB-backed queue and in-process worker for ingestion, evaluation and sync. |
| Access | services/access.py, query/access.py, rag.access |
AccessScope, clearance comparison, explicit document grants, staged preview. |
| Tools | tools/ |
ToolRegistry, ToolSpec, RestrictedToolInvoker, composite dependencies, masking, audit, MCP and HTTP-OpenAPI adapters. |
| Query facade | query/facade.py, api/query.py |
Intent recognition, retrieval, parent lookup, live tool calls, generation and observations. |
| Runtime app | app.py, settings.py, settings_section.py |
Standalone composition, settings block and runtime settings section. |
| Migrations | alembic/, migrate.py |
Own chain and version table alembic_version_rag_governance. |
| Test/demo doubles | testing/mock_kingdee/ |
Contract-compatible mock of the curated Kingdee read-only MCP tool set. |
| Reference scenario | examples/finance_kpi/ |
Seed corpus, metric catalog, rules, six-case golden set, composite tools, fixtures. |
Composition
A product build includes the package's routers in its own app (ADR-0015):
from cliver_playbook.app.rag_governance import ROUTERS as GOVERNANCE_ROUTERS
for router in GOVERNANCE_ROUTERS:
app.include_router(router)
create_app() in cliver_playbook.app.rag_governance.app assembles the
standalone stack (basic + user + rag + governance) for development and
tests. It binds the most-derived Settings with the runtime, so every
package's settings proxy sees the same instance (ADR-0016). It also puts an
empty ToolRegistry and the rule-based RuleToolPlanner on app.state; a
scenario registers its composite tools there at startup:
from examples.finance_kpi.tools import register
register(app.state.tool_registry) # after the vendor MCP tools are registered
Importing rag_governance registers its permission codes and settings section
before any router that references them, and reads no settings or database.
Settings
The process-wide block is rag_governance (CLIVER_RAG_GOVERNANCE__*);
project policy — approval mode, retrieval knobs, thresholds, tool bindings —
lives on the project row, not here.
| Field | Default | Meaning |
|---|---|---|
worker_enabled |
true |
Run the in-process job worker. |
worker_poll_seconds |
1.0 |
How often the worker claims a queued job. |
job_max_attempts |
3 |
Failures before a job is marked failed. |
job_retry_backoff_seconds |
2.0 |
Base delay; doubles per attempt. 0 is test-only. |
default_approval_mode |
manual |
Used only when a new project chooses no mode. |
mock_kingdee_url |
empty | Optional base URL of a local mock ERP for scenario startup code; empty disables it. |
max_tool_rows |
1000 |
Upper bound on rows a governed tool may return. |
Runtime edits go through the standard settings section
(rag_governance → Admin → Settings) and apply in place.
Permissions
Registered at import into the identity catalog:
| Code | Gates |
|---|---|
rag_governance:project:read / :write |
Viewing and editing projects. |
rag_governance:source:write |
Managing sources and triggering ingestion. |
rag_governance:golden:read / :write |
Viewing, editing, importing and confirming golden sets. |
rag_governance:rule:read / :write |
Viewing, editing and activating intent rules. |
rag_governance:eval:read / :run |
Viewing and running evaluations. |
rag_governance:approve |
Approving or rejecting a staged batch. |
rag_governance:staged:read |
Previewing unapproved staged documents. |
rag_governance:tool:read / :write |
Viewing and editing tool bindings. |
rag_governance:job:read |
Viewing background jobs. |
rag_governance:query:read |
Asking governed questions. |
staged:read is deliberately separate from project:read: seeing unapproved
data is the capability the approval gate withholds.
Migrations
The package owns its chain; migrate.py is the aggregate entry point that
runs every dependency's chain first (basic, user, rag, then governance):
python -m cliver_playbook.app.rag_governance.migrate \
--database-url postgresql+psycopg://cliver:cliver@127.0.0.1:15432/cliver_app
Omit --database-url to use the configured database_url
(CLIVER_DATABASE_URL / app.yaml / .env). Re-running is a no-op once the
database is current.
Local demo (isolated ports)
Other services on this machine may own 5432 and 8000. The demo uses offset
ports: test database 127.0.0.1:15432, standalone app 127.0.0.1:18000,
mock Kingdee 127.0.0.1:18080.
# 1. Isolated PostgreSQL with pgvector
docker run --rm -d --name cliver_gov_demo_db \
-p 127.0.0.1:15432:5432 \
-e POSTGRES_USER=cliver -e POSTGRES_PASSWORD=cliver -e POSTGRES_DB=cliver_app \
pgvector/pgvector:pg16
# 2. Schema
uv run python -m cliver_playbook.app.rag_governance.migrate \
--database-url postgresql+psycopg://cliver:cliver@127.0.0.1:15432/cliver_app
# 3. Mock Kingdee MCP server (curated read-only contract, period fixtures)
uv run python -m cliver_playbook.app.rag_governance.testing.mock_kingdee.server \
--fixtures examples/finance_kpi/fixtures/kingdee --period 2026-10 --port 18080
# 4. Standalone governance app
CLIVER_DATABASE_URL=postgresql+asyncpg://cliver:cliver@127.0.0.1:15432/cliver_app \
uv run uvicorn --factory cliver_playbook.app.rag_governance.app:create_app \
--host 127.0.0.1 --port 18000
The mock accepts JSON-RPC initialize / tools/list / tools/call at any
path, so a tool binding can point at http://127.0.0.1:18080/mcp. The finance
composites are registered by scenario startup code, not by core governance;
tests/test_finance_acceptance.py shows the full wiring. Stop the container
with docker stop cliver_gov_demo_db.
The reference scenario's fixtures are pinned to period 2026-10 with a data
cutoff of 2026-10-31T23:59:59+08:00; questions use the injected as_of,
never the host clock, so the demo is reproducible on any day.
Test
uv run pytest -v
The suite runs on a temporary SQLite database with no services required; the
PostgreSQL-specific migration test renders SQL offline. ruff check and
ruff format --check are the lint gates.
Optional MCP client
The outbound mcp-tool adapter speaks JSON-RPC over httpx and works with no
MCP SDK installed. Install the extra only for a deployment that wants the
SDK's stdio/session helpers:
pip install "cliver-playbook-app-rag-governance[mcp-client]"
The inbound cliver-playbook-app-mcp server is a separate package and is
never imported here.
Metadata
Release files for cliver-playbook-app-rag-governance 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cliver_playbook_app_rag_governance-0.2.1.tar.gz | 150.7 kB | Without provenance | Details for cliver_playbook_app_rag_governance-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cliver_playbook_app_rag_governance-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for cliver_playbook_app_rag_governance-0.2.1-py3-none-any.whl |
Total release size: 298.6 kB
Release files / cliver_playbook_app_rag_governance-0.2.1.tar.gz
| Download URL | cliver_playbook_app_rag_governance-0.2.1.tar.gz |
|---|---|
| Size | 150.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abec1429f3b6c1568501e4e839fcab6cf73954251f979bab82b57f4ccf18fc4e
|
|
BLAKE2b-256 checksum How to use checksums |
21b969b1433b37aa88d24c8597b9b710aa85dec6dd8c58a466dc6cc8e2048df6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cliver_playbook_app_rag_governance-0.2.1-py3-none-any.whl
| Download URL | cliver_playbook_app_rag_governance-0.2.1-py3-none-any.whl |
|---|---|
| Size | 147.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0434c1ab6b451b582f44df75586e68440f35ea756edb988cb25675b101fe0f0b
|
|
BLAKE2b-256 checksum How to use checksums |
e21347fa7a2a905fcc5bb34fade5cddb87c57fe5b54240d6cbacb531518daa94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cliver-playbook-app-rag-governance 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.