AgentSkillsCN

annotating-csv

通过向每行应用提示词,并新增一列以输出 AI 生成的结果,利用 OpenAI 对 CSV 行进行标注。适用于用户希望对 CSV 数据进行分类、提取、汇总,或为其添加 AI 生成的注释时。当用户提及 CSV 标注、逐行 AI 处理、批量分类,或在电子表格数据中新增 AI 列时,即可触发此功能。

SKILL.md
--- frontmatter
name: annotating-csv
description: Annotates CSV rows using OpenAI by applying a prompt to each row and adding a new column with AI-generated results. Use when the user wants to classify, extract, summarize, or add AI-generated annotations to CSV data. Triggers on mentions of CSV annotation, row-by-row AI processing, bulk classification, or adding AI columns to spreadsheet data.

CSV Annotation with OpenAI

Adds AI-generated annotations to CSV files by processing each row with a prompt.

Quick Start

bash
uv run annotate-csv.py "Classify sentiment as positive/negative/neutral" reviews.csv

Output: reviews_annotated.csv with new annotation column.

Dependencies install automatically on first run.

Core Usage

bash
uv run annotate-csv.py <prompt> <csv_file> [options]
OptionDescriptionDefault
-o, --outputOutput file path<input>_annotated.csv
-c, --columnAnnotation column nameannotation
--contextColumns to use (all or comma-separated)all
--modelOpenAI modelgpt-5-mini
--parallelismParallel workers10
--id-columnColumn for progress display-

Prompt Sources

Prompts can be inline or from a file:

bash
# Inline prompt
python annotate-csv.py "Extract the main topic" data.csv

# From file (for complex prompts)
python annotate-csv.py prompt.txt data.csv

Common Patterns

Classification:

bash
python annotate-csv.py "Classify sentiment: positive, negative, or neutral" feedback.csv -c sentiment

Extraction:

bash
python annotate-csv.py "Extract the product name mentioned" reviews.csv -c product --context "review_text"

Summarization:

bash
python annotate-csv.py "Summarize in one sentence" articles.csv -c summary

See EXAMPLES.md for more patterns and prompt templates.

Environment Setup

Requires OPENAI_API_KEY in .env file:

code
OPENAI_API_KEY=sk-...

Run with uv (recommended):

bash
uv run annotate-csv.py "Your prompt" data.csv

Or install dependencies first:

bash
uv pip install -r requirements.txt
python annotate-csv.py "Your prompt" data.csv

Workflow

  1. Preview data: Check CSV structure and columns
  2. Choose context: Decide which columns the AI needs to see
  3. Write prompt: Be specific about expected output format
  4. Test on subset: Try on a few rows first if large dataset
  5. Run full annotation: Process the complete file
  6. Validate results: Spot-check annotation quality

Writing Effective Prompts

  • Be explicit about output format (single word, phrase, sentence)
  • List valid categories for classification tasks
  • Specify what to do with ambiguous cases
  • Keep prompts focused on one task

See PROMPTS.md for prompt-writing guidance.

Troubleshooting

IssueSolution
API key errorCheck .env file has OPENAI_API_KEY
Column not foundVerify column names match CSV exactly
Rate limitsReduce --parallelism to 5 or lower
Empty annotationsCheck context columns have data