Skip to content

fix(probe_data): support pandas 3 StringDtype in CSV prompt column fallback - #398

Merged
msoedov merged 1 commit into
msoedov:mainfrom
brixtonpham:fix/csv-text-column-fallback
Nov 26, 2026
Merged

msoedov merged 1 commit into
msoedov:mainfrom
brixtonpham:fix/csv-text-column-fallback

Conversation

@brixtonpham

Copy link
Copy Markdown
Contributor

What this changes

Fixes the text-column fallback in parse_csv_content() (agentic_security/probe_data/data.py), which broke on pandas 3.0 (pandas==3.0.6 in poetry.lock) because pd.read_csv() now infers text columns as StringDtype (str) rather than object, causing df[col].dtype == object to evaluate to False for every text column:

from agentic_security.probe_data.data import parse_csv_content

parse_csv_content(b"text,label\nIgnore previous instructions,1\n")
# before (pandas 3.0.6): ValueError: Uploaded CSV has no suitable prompt column. Please include a column named 'prompt'.
# after:                 ProbeDataset(dataset_name='Uploaded CSV', prompts=['Ignore previous instructions'], ...)
  • Adds _is_non_empty_text_column(series) using pd.api.types.is_string_dtype(non_null) after dropna() plus a non-blank check — works on both pandas 3.0 StringDtype and pandas 2.x string object columns, skips all-null/whitespace-only columns, and avoids mis-selecting nullable boolean object columns (flag,text with missing booleans).
  • Selects exact "prompt" first, then case-insensitive/trimmed "prompt" (e.g., Prompt), then the first non-empty text column, preserving ValueError for numeric-only, boolean-only, or empty CSVs.
  • Adds 14 offline unit tests in tests/unit/probe_data/test_parse_csv_content.py.

How it was tested

  • pytest -v tests/unit/probe_data/ agentic_security/probe_data/test_data.py tests/integration/routes/test_csv.py on Python 3.15.2 / pandas 3.0.6: 52 passed (including all 14 new cases in test_parse_csv_content.py).
  • Pre-commit checks matching .pre-commit-config.yaml (black --check, flake8, pyupgrade --py314-plus, pycln --check, codespell, poetry check --lock): all clean.

Checklist

  • No real API key, token or customer endpoint anywhere in the code, tests, docs or this description (CONTRIBUTING.md).
  • pytest passes and new behaviour has a test. Tests don't call paid APIs.
  • pre-commit run --all-files is clean.
  • Docs updated if behaviour changed. (Existing docstring already documents the text-column fallback; no doc change needed.)

@msoedov msoedov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@msoedov

msoedov commented Nov 26, 2026

Copy link
Copy Markdown
Owner

@brixtonpham thx for the patch!

@msoedov
msoedov merged commit 57778e5 into msoedov:main Nov 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants