pythia for MongoDB: database development for AI agents over pythia-core - validators, views and indexes read live, impact with its blind spots named, and an approved write path.
pip install pythia-mongo==0.1.1 Copy PIP instructions
Alpha (0.1.1). It reads everything pythia's Learn movement needs, writes through one gate — data rehearsed in a transaction; validators, views and indexes predicted, written once, and read back — and wires a project for an agent: the guard, the session brief, the approval doors and the pythia-mongo-* skills.
MongoDB 7.0 and 8.0 are tested, each through the whole live check; 7.0 is the floor, and below it check says so (nothing is refused).
pip install pythia-mongo That brings pythia-core, and pymongo, the only driver it uses. The development version is the main branch of both:
pip install "git+https://github.com/thaildhe172591/pythia-core" \ "git+https://github.com/thaildhe172591/pythia-mongo" Set up a project for an agent cd your-project pythia-mongo install # once; a second run changes nothing pythia-mongo doctor # is everything wired? exit 1 names what is not install writes, and leaves everything else as it was:
Restart the agent's session after installing, so the hooks load. Each session then starts with the rules and a STATE line (connections, the write policy). Before every tool call the guard decides:
The guard reads a command for what it names, not what it means: it can deny a harmless command (a find that mentions .drop( in a string, or a runCommand that only reads) and miss a write spelled in a way it does not list. It sees the commands Claude Code hands its tools, not Compass or a driver inside the application. The gate behind it holds either way (pythia-core's SECURITY.md).
pythia-postgres and pythia-mssql install beside it in one project, and pythia for Oracle too: each keeps the others' hooks and instruction blocks, and each guard and approval hook acts for its own tool only (pythia-core's CI checks it with all four installed).
.pythia/mongo/connections.json in the project root, owner-readable only (chmod 600), and out of git. Template: examples/connections.example.json.
{ "default": "dev", "dev": { "host": "db-dev", "port": 27017, "database": "app", "user": "app_agent", "password": "...", "auth_source": "admin", "tls": false } } host and database are required. host may list several members ("a:27017,b:27017"). auth_source is the database the user lives in (default admin). tls (default false), replica_set, and direct (true talks to the one member named, not the set it advertises — for a member reached through a container's mapped port or a tunnel). A connection string ("uri") is refused: it carries the password into every place it is printed. The entry is picked by --conn NAME, then PYTHIA_MONGO_CONNECTION, then the only entry, the folder directly under the project root, then "default". PYTHIA_MONGO_CONFIG points at another file. pythia for Oracle keeps .pythia/connections.json, and the other engines their own folders; pythia-mongo reads none of them.
pythia-mongo check # server, replica set or not, database pythia-mongo ls "t_order%" # collections and views by LIKE pattern pythia-mongo src t_order # a validator, or a view's pipeline, as Extended JSON pythia-mongo cols t_order # fields and their types, from a sample of documents pythia-mongo ddl t_order # the commands that make it: create, createIndexes pythia-mongo grep PAID # every validator and pipeline line holding a text pythia-mongo deps v_order_lines # what a view reads pythia-mongo impact t_order # what reads it: run before changing it pythia-mongo errors [NAME] # documents a validator rejects, views that fail --json gives one envelope per command; --limit, --max-lines and --offset window long output, and any truncation says how to fetch the rest.
pythia-mongo apply change.json # preview: rehearsed or predicted, nothing kept pythia-mongo approve 3fa9c1 # the developer approves, at their own console pythia-mongo apply change.json --confirm 3fa9c1 # writes it — only as approved pythia-mongo journal restore # undo is a write too: preview, approve, confirm pythia-mongo policy # which groups may be written, and is rollback real? The developer approves through the first door that works:
pythia-mongo doctor warns about settings that would answer the chat door for the developer (dontAsk mode, an allow rule for AskUserQuestion, a hook matching every tool).
A file holds one command document, in Extended JSON — the document MongoDB itself takes, not mongosh JavaScript:
{"update": "t_order", "updates": [{"q": {"status": "DRAFT"}, "u": {"$inc": {"total": 1}}, "multi": true}]} apply sorts it into a group, and the policy decides: source — a view (create with viewOn, collMod of viewOn and pipeline) or a validator (collMod of validator, validationLevel, validationAction) — needs the developer's approval; structural (a new collection, createIndexes, dropIndexes, drop, other collMod options) and data_dml (insert, update, delete) are denied until the developer runs pythia-mongo policy set confirm at a console.
Data is rehearsed. An insert, update or delete runs inside a transaction and is aborted: the preview shows how many documents it touched, and an UPDATE or DELETE is approved on its documents — the count, a sample, and a fingerprint ($toHashedIndexKey over each document). If one joins, leaves or changes before the confirm, the confirm is refused. A document the validator rejects fails the rehearsal (MongoDB reports it in the reply, not as an error, and pythia-mongo reads the reply). Transactions need a replica set: on a standalone server data writes are refused — a single-node replica set is enough for development.
Everything else is predicted. MongoDB runs a view, a validator, an index or a dropped collection outside any transaction, so nothing can be run and rolled back. pythia-core's predict tier takes over: nothing runs before the approval, and the preview says "predicted — nothing ran".
After the approval core runs the command once. MongoDB applies each of these commands whole or not at all, so a refusal wrote nothing and keeps the approval; a command whose answer never came is reported WRITTEN? (exit 3). What landed is read back, and anything unlike the prediction is reported and exits 3 with the restore. A prediction runs for at most 30 seconds (maxTimeMS).
Refused, with the reason: mongosh JavaScript, several commands in one file, a key written twice, JavaScript anywhere ($where, $function, $accumulator, code), $out and $merge (a prediction runs a pipeline before approval: it must never write), reads (aggregate, find), findAndModify, an upsert, an update or delete of one document among many ("multi": true or "limit": 0, or name it by _id), users and roles, renameCollection, dropDatabase, bypassDocumentValidation, session and transaction fields (lsid, writeConcern, ...), and system. collections.
pythia-mongo deploy 01_fix.json 02_backfill.json # preview the release as one transaction pythia-mongo deploy 01_fix.json 02_backfill.json --confirm 9c41e0b2aa # all of it, as approved, or none A release is data: one or more files, each one command document or a JSON array of them, in the order they run. It is rehearsed in one transaction — each command in order, its documents counted and fingerprinted at its own point (an update of a document the release inserts sees it), then everything is aborted. One card shows every command, and one approval (a 10-digit token, through the same doors) covers the release; a single command's token cannot be approved alone. The confirm checks that every command is byte-identical to what was approved before anything runs, re-runs the release in one transaction, and commits only if every command still matches. A command that fails, or documents that moved, abort the whole release. A commit that does not answer is reported WRITTEN? for the whole release.
A validator, a view, an index or a new or dropped collection has no place in a release: MongoDB runs them outside any transaction, so they are predicted, not rehearsed, and could not land all or nothing. deploy refuses them before anything is written; apply each on its own. Anything apply refuses is refused here too.
pythia-mongo lint 01_fix.json 02_view.json # a change's files in one run pythia-mongo lint --rules # every rule and its effective severity The rules read what MongoDB accepts and a reviewer would not:
What MongoDB refuses itself is left to the rehearsal or the prediction. The team sets severities and naming patterns (a view's name, VIEW; a validator's collection, VALIDATOR) in .pythia/mongo/lint.json:
{"severity": {"mongo-validation-warn": "error", "naming": "error"}, "naming": {"VIEW": "^v_[a-z0-9_]+$"}} Every preview shows the findings, a command's errors are on its card, and autopilot never lands a lint error.
pythia-mongo autopilot request --groups source --hours 2 --max-writes 30 pythia-mongo autopilot report # every write under the lease, with its restore pythia-mongo autopilot off # anyone may revoke When the developer wants the agent to work without approving each write, the agent requests a lease. Its card names the connection, the groups, the time, the number of writes and whether destructive commands are included, and nothing is delegated until the developer approves it through a door (or runs pythia-mongo autopilot on at a console). While it lasts, apply and deploy land what it covers without --confirm — still snapshotted, rehearsed or predicted, read back and journaled. It never covers another connection, one marked "protected": true (or an "env" of prod / production / prd / live), a group or destructive command the card did not name, or more than 1000 documents; a write that breaks something, lands unlike its prediction or is WRITTEN?, or five failures in a row pause it.
The read commands need the read role on the database. Writing needs readWrite (data, indexes, new collections and views) and dbAdmin (collMod of a validator or a view); the preview warns when the user holds far more (root, dbOwner, any AnyDatabase role). The live check runs every read as a read user, and every write as one holding readWrite and dbAdmin.
python tests/test_mongo.py # no database, no pymongo — mutation-checked python tests/live_check.py # a disposable server only (see its docstring) CI runs the suite on Ubuntu, Windows and macOS, Python 3.9 and 3.13, and the live check — every read, every write path, a release, a lint finding in a real preview and a write under a lease — against MongoDB 7.0 and 8.0, each a single-node replica set with authentication. It tests against the pythia-core branch of the same name when one exists.
All 2 files in this release have provenance metadata.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
All 2 files in this release have been uploaded with provenance metadata.
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.




