PARAS MADAN
All writing

Latest in AI

Pydantic AI Conversation Stores: SQLite, Postgres or MongoDB?

Choose a backend for chat history, avoid the renamed Pax session import, and test what deletion actually removes.

If your Pydantic AI app needs to bring a chat back after a restart, use a conversation store. If it needs to recover an unfinished agent run, use step persistence. They solve different failures. Storing a conversation doesn't make an interrupted tool call safe to replay.

Pydantic AI 2.77 introduces three conversation backends in the Harness package: SQLite, PostgreSQL and MongoDB. All three give the app a way to reload chat history. The important difference shows up when you delete a conversation and check what remains in the database.

Choose according to what you need to keep

BackendWhere I'd startWhat deletion does
SQLiteA single-instance prototype or a local app with a persistent database fileRemoves the conversation and cleans up entries and messages that no other history or branch uses.
PostgreSQLAn app already using Postgres, especially one served by multiple workersUses similar cleanup rules. A concurrent write to a history being deleted can raise a conflict.
MongoDBA team already operating MongoDB and prepared to manage retained history separatelyRemoves the conversation record; stored entries and messages remain.

Those behaviors come from the backend documentation. Externalized media is not deleted by any of the three conversation stores. An attachment that disappears from the chat screen can still exist in a separate media store. If you're promising deletion to users, test both layers before choosing the backend.

Fix the import without changing the meaning

If you used the store behind Pax's session browser, the 2.77 release renamed its SqliteConversationStore to SqliteSessionStore and its ConversationConflict to SessionConflict. The old names in pydantic_ai_harness.step_persistence.conversations still import with a deprecation warning. Update those imports if you are still maintaining Pax-style session records.

For a new app conversation store, import SqliteConversationStore, PostgresConversationStore or MongoConversationStore from pydantic_ai_harness.conversation_store. Two different modules can contain the same old class name, so search your actual imports before doing a rename everywhere.

Test one conversation through restart, fork and delete

Create a test chat under an application-generated identifier and save two messages. Restart the worker, load the same conversation and add a third message. When a store is used directly, the persistence guide describes loading before the run and saving the result after it. If a UI adapter owns that process, confirm that it is actually configured with the store rather than sending browser-owned history on every call.

Fork the test chat from its first message. Delete the original and confirm it no longer loads, that the fork still reads its shared history, and that unshared records behave as the backend documents. Inspect the actual database and a disposable attachment instead of stopping at the user interface. Run concurrent saves as a separate test. A conflict is a reason to reload and decide what to keep, not to rerun a tool call that may have already sent a message or changed a record.

I'd use the database the team already knows how to operate, unless its deletion behavior conflicts with what the product promises. Solve that while the fixtures are still fake.

I'm Paras. I work with teams building AI tools.

I help explain runtime and storage decisions from the point of view of the developer who has to ship them.

Book a 30-minute call.