Contact Us

Tell us about your stack and the privacy problems you're trying to solve. We typically respond within one business day.

Prefer email? support@philterd.ai

Please do not enter PII or PHI in this form. If you need to share an example, use a sanitized one.

Knowledge base How-to

Column Rules for CSV and Excel in PhiSQL

Redact CSV files and Excel workbooks by column with PhiSQL: replace a column whole, leave one alone, or scan one with chosen filters, and set how a CSV file is read.

For PhiSQL and Phileas

In a spreadsheet or CSV export, a column has a meaning. Everything in Member SSN is a Social Security number, nothing in Claim ID is personal, and only Notes holds free text. Detection that treats every cell the same ignores that. It can miss a partial value such as 987-65 in the SSN column, and it scans columns that need no scanning.

Column rules put that knowledge in the policy. A rule replaces every value in a column with no detection, leaves a column unchanged, or scans it with only the filters that suit it. This guide writes them in PhiSQL, compiles them, and applies them to a CSV file and an Excel workbook. For the basics of the language, see Authoring redaction policies with PhiSQL.

A claims export has the columns Claim ID, Member, Member SSN, Phone, and Notes. Column rules leave Claim ID unchanged, replace every Member value, replace every Member SSN value including the partial 987-65 with no detection, scan Phone with every filter because it has no rule, and scan Notes with only the email filter. The redacted row keeps CLM-1002, replaces the name and the partial SSN, redacts the phone number, and keeps a phone number in Notes because that column is scanned only for email addresses.

Note: As of December 1, 2026, the PhiSQL compilers (Python 1.6.0, Java 1.7.0, .NET 1.6.0) compile column rules, but no released Philter or Phileas applies them. Phileas 4.5.0 and Philter 4.0.1 do not read CSV or Excel files: Philter 4.0.1 refuses text/csv with 415. Support is in Phileas’s main branch, published as 4.6.0-SNAPSHOT, which is what the output below comes from, and in Philter’s main branch. Philter 4.0.1 still accepts a policy with column rules: it stores the JSON, ignores the rules, and applies the policy’s identifiers to text. The PhiSQL catalog says a runtime without column rules should reject such a policy instead, so do not take its acceptance as support.

The policy

claims-export.phisql covers a semicolon-separated claims export and a workbook with a Members worksheet:

POLICY claims_export;

REDACT EMAIL_ADDRESS, PHONE_NUMBER WITH REDACT;

CONFIGURE CSV (delimiter = ';');

CONFIGURE TABULAR SHEET (
  headerRows = 1,
  unlistedColumns = 'identifiers',
  columns = [
    (header = 'Member', action = 'redact', strategies = [(strategy = 'REDACT')]),
    (header = 'Member SSN', action = 'redact', strategies = [(strategy = 'MASK')]),
    (header = 'Claim ID', action = 'ignore'),
    (header = 'Notes', action = 'filter', filters = ['emailAddress'])
  ]
);

CONFIGURE TABULAR SHEET (
  worksheet = 'Members',
  unlistedColumns = 'redact',
  columns = [
    (header = 'Member ID', action = 'ignore'),
    (header = 'Plan', action = 'ignore')
  ]
);

CONFIGURE CSV sets how a CSV file is read: delimiter (default ,), quote (default "), and encoding (default UTF-8). It has no effect on Excel workbooks.

Each CONFIGURE TABULAR SHEET statement adds one sheet entry:

  • worksheet names the worksheet the entry applies to, compared without regard to case. An entry without one applies to every worksheet that has no entry of its own, and to a CSV file.
  • headerRows is the number of header rows, 1 by default. Header rows are never redacted. Rules match their header against the last header row. With 0, columns can only be picked by index, counting from 1.
  • unlistedColumns decides what happens to columns without a rule. identifiers, the default, scans them with every filter in the policy. ignore leaves them unchanged. redact replaces every value with unlistedStrategies (one REDACT by default), which makes the entry an allow-list: only columns with a rule survive.
  • Each rule in columns picks a column by header or index and has an action:
    • redact replaces every value with strategies, with no detection.
    • ignore leaves the column unchanged.
    • filter scans each cell with only the filters named, by their key in the compiled identifiers (emailAddress, not EMAIL_ADDRESS).

When a header rule and an index rule pick the same column, the more protective one applies: redact, then filter, then ignore. The keywords CSV, TABULAR, and SHEET are not reserved, so they remain usable as names elsewhere.

Compile it

Compile with any of the reference compilers. All three produce the same policy, with different JSON formatting. With the Python one:

pip install phisql==1.6.0
phisql claims-export.phisql > claims-export.json

The rules compile to a top-level tabular section beside identifiers, and the CSV settings to config.csv:

{
  "identifiers": {
    "emailAddress": { "emailAddressFilterStrategies": [ { "strategy": "REDACT" } ] },
    "phoneNumber": { "phoneNumberFilterStrategies": [ { "strategy": "REDACT" } ] }
  },
  "config": {
    "csv": { "delimiter": ";" }
  },
  "tabular": {
    "sheets": [
      {
        "headerRows": 1,
        "unlistedColumns": "identifiers",
        "columns": [
          { "header": "Member", "action": "redact", "strategies": [ { "strategy": "REDACT" } ] },
          { "header": "Member SSN", "action": "redact", "strategies": [ { "strategy": "MASK" } ] },
          { "header": "Claim ID", "action": "ignore" },
          { "header": "Notes", "action": "filter", "filters": [ "emailAddress" ] }
        ]
      },
      {
        "worksheet": "Members",
        "unlistedColumns": "redact",
        "columns": [
          { "header": "Member ID", "action": "ignore" },
          { "header": "Plan", "action": "ignore" }
        ]
      }
    ]
  }
}

(The compiler writes one value per line. The JSON above is condensed.)

The compiler rejects rules that could not work, before the policy goes anywhere:

compile error: column filter 'ssn' is not defined in identifiers
compile error: More than one column rule for header 'SSN'
compile error: A redact column rule needs strategies

The first comes from filters = ['ssn'] in a policy with no SSN filter, the second from two rules for the same header, and the third from a redact rule without strategies.

Apply it

The input files hold invented data. claims.csv:

Claim ID;Member;Member SSN;Phone;Notes
CLM-1001;Jane Roe;123-45-6789;(217) 555-0142;Asked for a call back, email jane.roe@example.com
CLM-1002;John Doe;987-65;(217) 555-0175;Partial SSN on the form, call (217) 555-0199

claims.xlsx has a Claims worksheet with the same rows, and a Members worksheet:

Member IDNameDate of BirthPlan
M-2001Jane Roe1980-02-14Gold
M-2002John Doe1975-07-30Silver

This Java program applies the compiled policy with Phileas, using CsvFilterService for the CSV file and OoxmlFilterService from the phileas-ooxml module for the workbook:

package com.example;

import ai.philterd.phileas.PhileasConfiguration;
import ai.philterd.phileas.model.filtering.BinaryDocumentFilterResult;
import ai.philterd.phileas.model.filtering.MimeType;
import ai.philterd.phileas.policy.Policy;
import ai.philterd.phileas.services.context.DefaultContextService;
import ai.philterd.phileas.services.disambiguation.vector.InMemoryVectorService;
import ai.philterd.phileas.services.filters.filtering.CsvFilterService;
import ai.philterd.phileas.services.filters.filtering.OoxmlFilterService;
import com.google.gson.Gson;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

public class ApplyColumnRules {

    public static void main(String[] args) throws Exception {
        final Policy policy = new Gson().fromJson(Files.readString(Path.of("claims-export.json")), Policy.class);
        final PhileasConfiguration configuration = new PhileasConfiguration(new Properties());

        final CsvFilterService csv = new CsvFilterService(configuration,
                new DefaultContextService(), new InMemoryVectorService(), null);
        final BinaryDocumentFilterResult csvResult = csv.filter(policy, "claims",
                Files.readAllBytes(Path.of("claims.csv")), MimeType.TEXT_CSV);
        Files.write(Path.of("claims-redacted.csv"), csvResult.getDocument());
        csvResult.getWarnings().forEach(w -> System.out.println("warning: " + w));

        final OoxmlFilterService xlsx = new OoxmlFilterService(configuration,
                new DefaultContextService(), new InMemoryVectorService(), null);
        final BinaryDocumentFilterResult xlsxResult = xlsx.filter(policy, "claims",
                Files.readAllBytes(Path.of("claims.xlsx")), MimeType.APPLICATION_XLSX);
        Files.write(Path.of("claims-redacted.xlsx"), xlsxResult.getDocument());
        xlsxResult.getWarnings().forEach(w -> System.out.println("warning: " + w));
    }
}

claims-redacted.csv:

Claim ID;Member;Member SSN;Phone;Notes
CLM-1001;{{{REDACTED-full-column}}};***********;{{{REDACTED-phone-number}}};Asked for a call back, email {{{REDACTED-email-address}}}
CLM-1002;{{{REDACTED-full-column}}};******;{{{REDACTED-phone-number}}};Partial SSN on the form, call (217) 555-0199

Row by row, column by column:

  • Claim ID is unchanged, as its ignore rule says.
  • Every Member value is replaced. A REDACT strategy in a column rule writes {{{REDACTED-full-column}}}.
  • Every Member SSN value is masked, including the partial 987-65. The rule replaces the column whatever it holds, with no detection involved.
  • Phone has no rule, so it is scanned with every filter in identifiers, and the phone filter redacts it.
  • Notes is scanned only with emailAddress. The email address is redacted, and the phone number in the second row is kept. That is what the rule says, so add 'phoneNumber' to its filters if free-text phone numbers matter.

In claims-redacted.xlsx, the Claims worksheet has no entry of its own, so it follows the entry without a worksheet and comes out exactly like the CSV file. The Members worksheet follows its allow-list entry:

Member IDNameDate of BirthPlan
M-2001{{{REDACTED-full-column}}}{{{REDACTED-full-column}}}Gold
M-2002{{{REDACTED-full-column}}}{{{REDACTED-full-column}}}Silver

Name and Date of Birth have no rule, so unlistedColumns = 'redact' replaces them. A column added to the export later is replaced as well until it gets an ignore rule.

Watch for headers that do not match

A rule matches a header by its exact text, trimmed. If an export renames Member SSN to SSN, the rule matches nothing, and the column falls back to unlistedColumns. With this policy, which has no SSN filter, the SSN values then pass through unchanged:

Claim ID;Member;SSN;Phone;Notes
CLM-1001;{{{REDACTED-full-column}}};123-45-6789;{{{REDACTED-phone-number}}};Asked for a call back, email {{{REDACTED-email-address}}}
CLM-1002;{{{REDACTED-full-column}}};987-65;{{{REDACTED-phone-number}}};Partial SSN on the form, call (217) 555-0199

Phileas returns a warning for each rule that matched no column, which the program above prints:

warning: The column rule for header 'Member SSN' matches no column.

Treat that warning as a failure in any automated pipeline, and include the SSN filter in identifiers as a second line of defense for columns that fall through. Detection in filter and unlisted columns is probabilistic, and a redact rule is only as good as the export’s headers, so check redacted output against your own files.

Where to go next