Your data is not corrupted. When a text value in a CSV file from etlmcp begins with =, +, -, @, a tab or a carriage return, etlmcp writes a single apostrophe in front of it. A campaign called -Brand arrives as '-Brand, and one called =Promo arrives as '=Promo. The apostrophe makes a spreadsheet app treat the value as text, not as a formula, when you open the file. Your stored data is unchanged: only the CSV copy carries the extra character.
Why etlmcp does this
Campaign, ad set and ad names are typed by people, and anyone with access to an ad account can name a campaign. A spreadsheet that opens a CSV file treats a cell that starts with one of those characters as a formula and may run it, so a name built to look like a formula could harm your computer or copy data out of your open spreadsheets. This attack is known as CSV injection or formula injection. OWASP's page on CSV injection counts all six of these characters (=, +, -, @, tab and carriage return) among those that start a formula. It names a leading single quote as one way to neutralise a cell, and warns that this is not reliable in Microsoft Excel once the file has been saved and opened again.
Where the apostrophe appears
The rule applies to every CSV file etlmcp writes, to header cells as well as data cells:
- the Download CSV button on the Data page, which gives you every stored row in the date range you pick;
- the CSV file each pipeline run writes to a CSV export destination, which you download from the pipeline page or from the list of exported files on the Data page;
- the CSV files of the Amazon S3 destination, when that destination is available.
The standard column names all start with letters, so in practice you see the apostrophe in values, not in the header row.
It does not appear anywhere else. The JSON data endpoint, the query_data MCP tool and the PostgreSQL destination return or write text values without the apostrophe.
What is and is not changed
- Only text values are checked. A value held as a number, such as
costorimpressions, is written as it is, so a negative spend of -1.5 stays-1.5. - An identifier that is stored as text is still text. An account id stored as the text
-5is written as'-5. - Empty values stay empty, and nested values are written as JSON, which starts with
{or[and is never prefixed. - etlmcp checks the first character only, and only those six characters. Values that begin with a line feed or with full-width versions of these symbols, which OWASP also lists, are not prefixed.
Removing the apostrophe before you load a file
If you open the file in a spreadsheet to read it, leave the apostrophe: it is what keeps the cell as plain text. If you load the file into a database or a script, remove it there. Remove it only when it is followed by one of the six characters, so that an apostrophe that is really part of a name, such as 'Tis the season, is kept.
In PostgreSQL, after you copy the file into a staging table:
UPDATE staging_ads
SET campaign_name = regexp_replace(campaign_name, '^''([-=+@\t\r])', '\1');
In Python with pandas, for every text column:
import re
pattern = re.compile(r"^'(?=[-=+@\t\r])")
for col in df.select_dtypes(include="object"):
df[col] = df[col].str.replace(pattern, "", regex=True)
One case cannot be undone this way. A name that truly began with an apostrophe followed by one of those characters, such as '=x, looks the same in the file as =x with the prefix added, so the step above turns both into =x. If you need text values without the added apostrophe, load them through the PostgreSQL destination or the JSON endpoint instead of a CSV file; see download links and expiry for how long exported files stay available.