All insights

AI security and compliance

Soft delete vs hard delete in SaaS: AI, GDPR and audits

Delete removes the row. It also removes your answer to the question "what happened?"

Datics AI, Datics AIUpdated 10 min read

In brief

Soft delete vs hard delete comes down to history versus true removal. A soft delete flags a row as deleted and hides it, so it can be restored and audited. A hard delete removes the row for good. In established software, keep business records with a soft delete or a status, and erase personal data through a controlled purge that also reaches backups, search indexes, embeddings and AI logs.

On this page
  1. 01What soft delete and hard delete actually do
  2. 02Why delete is the wrong default in regulated products
  3. 03Soft delete vs hard delete: suppress, archive and purge
  4. 04How to implement soft delete without the usual bugs
  5. 05What deletion means once AI is involved
  6. 06What an audit trail must hold
  7. 07What we see in production
  8. 08A day-one checklist
  9. Frequently asked questions

01What soft delete and hard delete actually do

A soft delete keeps the row and marks it as deleted, usually with a deleted_at timestamp, an is_deleted flag or a status column. Normal queries filter it out, so users stop seeing it, but the data, its relationships and its history stay in the database. A hard delete runs a real DELETE, and the row is gone. Getting it back means restoring from a backup.

```sql -- Soft delete: hide the row, keep it UPDATE customers SET deleted_at = now() WHERE id = 42;

-- Restore is one statement UPDATE customers SET deleted_at = NULL WHERE id = 42;

-- Hard delete: the row is gone DELETE FROM customers WHERE id = 42; ```

Soft deleteHard delete
What happens to the rowStays, flagged or given a statusRemoved from the table
UndoOne update, if nothing else changedOnly from a backup
Audit and disputesHistory stays queryableHistory is gone unless logged elsewhere
Foreign keysChildren still point to a live rowDatabase cascades, blocks or nulls them
Unique values such as emailStay taken unless the index allows for itFreed immediately
Query effortEvery read must filter deleted rowsNothing to filter
StorageGrows over timeShrinks
Privacy erasureNot erasure on its ownNeeded, but must reach every copy
Best fitOrders, invoices, requests, accounts, anything evidenceTokens, sessions, temporary data, erased personal data

Most production systems need both. The real decision is which data gets which treatment, and who may trigger each. This is part of our larger guide, AI security for SaaS: protect data and pass security reviews.

02Why delete is the wrong default in regulated products

In a regulated workflow, a record is evidence. A transcript request ties together who asked, who approved, what price was set, when payment cleared and when the file was released. If any of those rows can disappear, the chain breaks, and the next dispute is decided by memory instead of data.

Health regulation in the U.S. makes the expectation explicit. The HIPAA Security Rule requires mechanisms that record and examine activity in systems holding protected health information, and policies that protect that information from improper alteration or destruction. Other regulated industries have their own versions. Hard delete works against both: you cannot examine activity on a record that is gone, and an unrestricted delete button is, by definition, uncontrolled destruction.

03Soft delete vs hard delete: suppress, archive and purge

Most products have one "delete" action that is asked to do three jobs. Splitting them is the core design decision.

Table comparing suppress, archive and purge by what users see, what happens to data and who can act
Suppress is the everyday action; purge should be logged, reviewed and rare.

Suppress is the everyday action: the record leaves search and lists, and its history stays. It answers "I do not want this shown" without answering "this never existed". Archive handles lifecycle, such as closed accounts and former staff, and can be restored by an owner or admin with a reason. Purge is the hard delete. It exists for legal erasure, retention expiry and data the user has the right to have removed, and it should be logged, reviewed and rare. Purge should always be harder to trigger than suppress.

A common way to connect them is a grace period: suppress now, keep the record restorable for a set window, then let a scheduled job purge what retention rules say must go.

04How to implement soft delete without the usual bugs

Soft delete has critics, and they have a point. In his essay on soft deletion, Brandur Leach argues that it is often not worth it: the deleted_at IS NULL filter has to appear in every query, foreign keys stop protecting you, pruning old rows gets hard, and undelete is rarely used because deletion also has side effects outside the database. These are the fixes we apply.

Filter in one place. Put the visibility rule in a database view, row level security or the data access layer, not in every query. ORM default scopes help, but direct SQL, reports and exports bypass them. A missed filter is how a suppressed record reappears in search.

``sql CREATE VIEW active_customers AS SELECT * FROM customers WHERE deleted_at IS NULL; ``

Fix unique constraints with a partial index. If a soft deleted user still holds an email address, a plain unique index blocks that person from signing up again. PostgreSQL supports a partial unique index, which enforces uniqueness only among rows that match a condition:

``sql CREATE UNIQUE INDEX users_email_active ON users (email) WHERE deleted_at IS NULL; ``

Decide cascades on purpose. With a hard delete, the foreign key rule (cascade, restrict or set null) decides what happens to children. With a soft delete, the database does nothing, so write down per table whether suppressing an account also suppresses its projects, files and invoices.

Model state, not a deleted flag. A status such as active, suppressed or archived is clearer than a timestamp named deleted_at in status driven workflows.

Use an archive table where history is rarely read. Brandur's alternative is to hard delete the row and copy it as JSON into a single deleted records table in the same statement. That keeps live tables clean and foreign keys honest, and makes retention pruning a single query:

``sql WITH removed AS ( DELETE FROM invoices WHERE id = 42 RETURNING * ) INSERT INTO deleted_record (table_name, record_id, data) SELECT 'invoices', id, to_jsonb(removed) FROM removed; ``

Test restore. If archive promises restore, test it, including side effects a flag cannot undo, such as emails already sent.

05What deletion means once AI is involved

Once a product has retrieval, assistants or agents, a customer record no longer lives in one row. Copies spread into places the original delete never touches:

  • Embeddings and vector indexes. Chunks of a document or ticket are stored as vectors with metadata. Suppressing the source row does not stop a retrieval pipeline from returning its chunks.
  • Search indexes and caches. Full text indexes and answer caches keep serving content after the source is hidden.
  • Prompt and response logs. Inputs and outputs hold the same personal data, sometimes in a vendor account.
  • Evaluation and training data. Real cases copied into test sets or fine tuning data outlive the account.
  • Audit logs and backups. These must record that something happened without keeping the erased content.

Treat a suppress as an event that every downstream copy listens for. When a record is suppressed, remove or filter its chunks from retrieval at the same moment; otherwise an assistant can quote a document that the user interface no longer shows, which is a textbook AI data leak. Vector stores support this directly. Pinecone's delete API, for example, deletes by record ID, by metadata filter, or empties a whole namespace, and it notes that the store is eventually consistent, so a delete may take a moment to show up in queries. Tag every chunk with its source record ID and tenant ID so that deletes are exact.

Per tenant deletion is the same problem at a larger scale. When a customer leaves, their rows, files, vectors, cached answers and logs must go, provably. With each tenant in its own namespace or partition, that is one operation; with tenants mixed in shared indexes, it is a row by row hunt. That is a strong argument for tenant isolation from the first AI feature.

Erasure law reaches these copies too. Under GDPR Article 17, a person can ask for erasure "without undue delay" on grounds such as withdrawn consent, with exceptions that include a legal obligation and the defense of legal claims. The UK regulator's right to erasure guidance expects a response within one month, expects erasure from backup systems as well as live ones, and accepts that backup copies may remain until overwritten only if they are put "beyond use". Models are harder still: the European Data Protection Board said in December 2024 that whether a model trained on personal data is anonymous must be judged case by case, which is a good reason to keep personal data out of fine tuning sets in the first place. Confirm the obligations that apply to you with your own counsel; the engineering answer is the same either way: know every place a record is copied, and make the purge reach all of them. Our guide to AI data security covers the controls around those stores, and AI data quality covers keeping suppressed or stale records out of what models read.

06What an audit trail must hold

An audit trail is useful only if it answers questions people actually ask in a dispute or a review. Design it backward from those questions:

Five stacked questions an audit trail must answer: who acted, what changed, which record, when and why
Tie the whole lifecycle to one identifier from the start.
  1. 01

    Who acted?

    The authenticated user, with their role at that moment, not just an account ID.

  2. 02

    What changed?

    The action and the before and after values for the fields that matter.

  3. 03

    On which record?

    A stable identifier that ties every event in a lifecycle together, such as one request ID across request, approval, pricing, payment and release.

  4. 04

    When?

    Server time, consistently recorded.

  5. 05

    Why, where it matters?

    A reason for overrides, suppressions of sensitive records, purges and manual corrections.

Keep the audit trail as an append only record of events, not something reconstructed from the current state of rows. Then even a purge leaves a minimal entry that something was removed, when and by whom, without keeping the erased content. Retrofitting a lifecycle ID across tables that grew separately is one of the most expensive changes we see in mature products, and it blocks AI features later. An agent that acts in your product needs the same audit trail a person does. For how that plays out when adding agents, see how to add AI agents to an existing SaaS product.

07What we see in production

Transcripts U.S. runs a national marketplace where court reporting agencies make deposition transcripts discoverable and attorneys request, pay for and receive copies. Suppress replaced delete, so a record keeps its history: agencies review each record and publish or suppress it, with Published, Needs Attention and Suppressed statuses, and attorneys search only published records. Questions, request, approval, price, payment, release and every timestamp hang off one Request ID, with complete audit events. The same project shows the cheapest deletion of all: title page details are extracted in the agency's browser, so the full transcript never reaches the platform's servers during discovery, and only the fields the agency approves are sent.

For Coast Technology's package and invoicing platform for RV dealership groups, we built five roles with managers limited to their assigned locations, inactive users blocked from signing in, and an activity log. Invoices carry explicit statuses, from Pending Financing to paid, so status changes, not deletions, tell the financial story of each deal.

In the Inzer gym product, admin profiles soft delete and restore across super admin, gym admin and branch admin consoles, a need that arrived when Inzer asked for one owner to run several gyms. Members delete their own records and accounts after re-entering their password, and member ID numbers are stored encrypted. That split is the pattern in small form: staff records are archived with restore, and personal data the member owns can be erased by the member, deliberately.

A lifecycle ID, status driven records, an audit trail and data you never collected are ordinary engineering decisions that make AI safe to add later.

08A day-one checklist

  1. 01

    Replace the generic delete with suppress, archive and purge, each with its own permission.

  2. 02

    Put visibility filtering in one shared layer, and use partial unique indexes for values such as email.

  3. 03

    Write down, per table, what happens to children when a parent is suppressed or purged.

  4. 04

    Choose one identifier that follows each business lifecycle end to end.

  5. 05

    Write audit events to an append only store with actor, role, action, record, time and reason.

  6. 06

    Tag every embedding, cache entry and log line with its source record ID and tenant ID.

  7. 07

    Define retention rules and build the purge job, including vectors, search indexes, logs and backups, before you need it.

  8. 08

    Give users a deliberate, confirmed way to erase data they own.

  9. 09

    Test restore, and test that suppressed records stay hidden everywhere, including exports, search and AI answers.

Frequently asked questions

Does soft delete satisfy a request to erase data?

No. A soft delete hides a record, but the record and its history stay. Data the law or the user requires you to erase needs a purge path that removes it from live tables, derived copies such as search indexes and embeddings, and logs, with backups put beyond use until they are overwritten. A minimal audit entry can still record that something was removed, when and by whom.

How do you handle unique constraints with soft delete?

Use a partial unique index that only covers active rows, such as a unique index on email where deleted_at is null. The suppressed row keeps its value for history, and a new account can use the same email. Databases without partial indexes need another approach, such as clearing or rewriting the value at suppression time.

Do I need to delete embeddings when a record is deleted?

Yes, or at least stop them from being retrieved at the same moment. Embeddings and their stored text are copies of the source, and an assistant can quote them after the record is hidden. Tag each chunk with its record and tenant IDs so deletes are exact.

Where should the soft delete filter live?

In one place: a database view, row level security or the data access layer, not every query. Each query that must remember the filter is a chance for a suppressed record to reappear.

Is a separate table of deleted records a good alternative?

It is a reasonable way to implement archive. It keeps foreign keys working and makes pruning simple, at the cost of harder restores. The mechanism matters less than the timing: decide how records are suppressed, archived and purged before the first customer depends on the history.

How Datics helps

Datics specializes in Brownfield AI: production AI inside software people already rely on. Already built AI? The AI Scorecard tests it on 50 of your own cases in two weeks, for $5,000, and ranks what to fix first. Once it is live, AI Care keeps it accurate for $1,500 a month per capability.

›References (7)
  1. 45 CFR 164.312: Technical safeguards, HIPAA Security Rule (Cornell Law School LII)
  2. Brandur Leach on soft deletion (brandur.org)
  3. PostgreSQL documentation: partial indexes
  4. Pinecone documentation: delete records
  5. GDPR Article 17: right to erasure (gdpr-info.eu)
  6. ICO: right to erasure guidance
  7. EDPB opinion on AI models and GDPR principles, December 2024

Related work

Case studies from our projects on the same subject.

Transcripts U.S.

Legal Tech · Legal transcript marketplace

Court reporting agencies publish transcript metadata without the file ever leaving their browser

Agencies once uploaded full transcripts to the marketplace; now title page details are read in their own browser, and they confirm what is published.

Brownfield AIInside a live productDocument intelligence
Read case study

Coast Technology

Automotive · Package sales and invoicing platform

RV dealers build add-on packages, invoice them and see profit per deal

Advisers needed packages built from inventory and invoiced through financing. Now one platform does both and shows profit per deal.

Data foundationPermission-awareMulti-tenant
Read case study

Inzer

Healthcare · Gym floor tablet and member app

Gym members learn each machine and log every set on its shared tablet

Members relied on trainers and handwritten logs. Now the tablet on each machine shows how to use it and logs every set.

Data foundationMulti-tenantPermission-aware
Read case study

More on AI security and compliance

AI security and compliance

AI security for SaaS: protect data and pass security reviews

A practical map of AI security for established SaaS: threats, data governance, permissions, audit trails and how to answer enterprise security reviews.

Umair MajeedRead

AI security and compliance

How do you stop AI data leakage through search metadata?

Stop AI data leakage in search by treating metadata as sensitive: classify records, automate high stakes rules, keep people on unclear cases, and audit.

Rana Umar MajeedRead

AI security and compliance

How do you enforce tenant isolation beyond database rows?

Tenant isolation beyond database rows means boundaries per field and per role, in caches, files, payments and jobs, so no tenant sees what another owns.

Rana Umar MajeedRead

AI security and compliance

LLM security: why treat model output as untrusted input?

A core LLM security rule: treat every model response like input from an unknown user. Parse it, validate it against business rules, then let it through.

Rana Umar MajeedRead

AI security and compliance

HIPAA AI compliance: BAAs, PHI in prompts and audit logs

HIPAA AI for software teams: which model providers sign a BAA, how to keep PHI out of prompts and logs, and where the 2025 to 2026 HHS rules stand.

Umair MajeedRead

AI security and compliance

How do you build an AI audit trail you can reproduce?

An AI audit trail records who or what made each change, with which inputs and model, so reviewers can tell AI entries apart and reproduce any output.

Rana Umar MajeedRead

Your customers already expect AI from your product.

Let us make it real inside the product you run today.