Package com.tnsai.tools.file
Class CsvTools
java.lang.Object
com.tnsai.tools.file.CsvTools
Function-shape CSV tools — the LangChain-style replacement for the legacy
monolithic
CSVParserTool that crammed five operations into a single
path|||command text protocol (see issue #188 — RFC).
Each operation here is a separate Tool-annotated method:
| Method | Purpose |
|---|---|
csvSummary(java.lang.String) | Row/column counts, fill ratios, preview |
csvColumns(java.lang.String, java.util.List<java.lang.String>) | Extract specific named columns |
csvFilter(java.lang.String, java.lang.String, java.lang.String) | Filter rows by case-insensitive substring on a column |
csvHead(java.lang.String, int) | First N rows |
csvSearch(java.lang.String, java.lang.String) | Search every cell for a substring |
All methods accept either an absolute file path (begins with / or
ends in .csv) or a literal CSV string. Same path-detection rule as
the legacy tool, kept verbatim so consumers migrating from csv_parser
see no behavior change other than the typed parameters.
- Since:
- 0.5.7 (Phase 2 — built-in tool migration to function shape, see #188)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
DEFAULT_EXTENSIONS
-
-
Constructor Details
-
CsvTools
public CsvTools() -
CsvTools
-
-
Method Details
-
csvSummary
@Tool(name="csv_summary", description="Summarize a CSV file: total rows, total columns, per-column non-empty / unique-value counts, plus a 5-row preview table. Use this when the user wants a high-level look at a CSV.", keywords={"csv","summary","overview","describe"}, idempotent=true) public String csvSummary(@ToolParam(description="Absolute file path to a .csv (or a literal CSV string)") String path) throws IOException, com.opencsv.exceptions.CsvException - Throws:
IOExceptioncom.opencsv.exceptions.CsvException
-
csvColumns
@Tool(name="csv_columns", description="Extract a specified subset of columns from a CSV. Columns match case-insensitively by header name; numeric strings fall back to positional index. Returns a Markdown ASCII table of at most 100 rows.", keywords={"csv","columns","select","project"}, idempotent=true) public String csvColumns(@ToolParam(description="Absolute file path to a .csv (or a literal CSV string)") String path, @ToolParam(description="Column names to extract (case-insensitive); supports numeric index strings") List<String> columns) throws IOException, com.opencsv.exceptions.CsvException - Throws:
IOExceptioncom.opencsv.exceptions.CsvException
-
csvFilter
@Tool(name="csv_filter", description="Return rows whose value in the named column contains the given value (case-insensitive substring). Returns a Markdown ASCII table capped at 100 rows.", keywords={"csv","filter","where","search"}, idempotent=true) public String csvFilter(@ToolParam(description="Absolute file path to a .csv (or a literal CSV string)") String path, @ToolParam(description="Column to filter on (case-insensitive name or numeric index)") String column, @ToolParam(description="Substring the column must contain (case-insensitive)") String value) throws IOException, com.opencsv.exceptions.CsvException - Throws:
IOExceptioncom.opencsv.exceptions.CsvException
-
csvHead
@Tool(name="csv_head", description="Return the first N data rows of a CSV as a Markdown ASCII table. Headers are always included. Cap is 100 rows.", keywords={"csv","head","preview","top"}, idempotent=true) public String csvHead(@ToolParam(description="Absolute file path to a .csv (or a literal CSV string)") String path, @ToolParam(description="Number of data rows to return (1..100, negative or zero clamped to 0)") int n) throws IOException, com.opencsv.exceptions.CsvException - Throws:
IOExceptioncom.opencsv.exceptions.CsvException
-
csvSearch
@Tool(name="csv_search", description="Find every row in a CSV where ANY cell contains the given substring (case-insensitive). Returns a Markdown ASCII table capped at 100 rows.", keywords={"csv","search","grep","find"}, idempotent=true) public String csvSearch(@ToolParam(description="Absolute file path to a .csv (or a literal CSV string)") String path, @ToolParam(description="Substring to search for (case-insensitive)") String text) throws IOException, com.opencsv.exceptions.CsvException - Throws:
IOExceptioncom.opencsv.exceptions.CsvException
-