|
| 1 | +--- |
| 2 | +title: classify |
| 3 | +description: API reference for the EveryRow classify tool, which assigns each row of a dataset into one of the provided categories using web research. |
| 4 | +--- |
| 5 | + |
| 6 | +# Classify |
| 7 | + |
| 8 | +`classify` takes a DataFrame and a list of allowed categories, then assigns each row to exactly one category using web research that scales to the difficulty of the classification. Supports binary (yes/no) and multi-category classification with optional reasoning output. |
| 9 | + |
| 10 | +## Examples |
| 11 | + |
| 12 | +### GICS sector classification |
| 13 | + |
| 14 | +```python |
| 15 | +from pandas import DataFrame |
| 16 | +from everyrow.ops import classify |
| 17 | + |
| 18 | +companies = DataFrame([ |
| 19 | + {"company": "Apple"}, |
| 20 | + {"company": "JPMorgan Chase"}, |
| 21 | + {"company": "ExxonMobil"}, |
| 22 | + {"company": "Pfizer"}, |
| 23 | + {"company": "Procter & Gamble"}, |
| 24 | + {"company": "Tesla"}, |
| 25 | + {"company": "AT&T"}, |
| 26 | + {"company": "Caterpillar"}, |
| 27 | + {"company": "Duke Energy"}, |
| 28 | + {"company": "Simon Property Group"}, |
| 29 | +]) |
| 30 | + |
| 31 | +result = await classify( |
| 32 | + task="Classify this company by its GICS industry sector", |
| 33 | + categories=[ |
| 34 | + "Energy", "Materials", "Industrials", "Consumer Discretionary", |
| 35 | + "Consumer Staples", "Health Care", "Financials", |
| 36 | + "Information Technology", "Communication Services", |
| 37 | + "Utilities", "Real Estate", |
| 38 | + ], |
| 39 | + input=companies, |
| 40 | +) |
| 41 | +print(result.data[["company", "classification"]]) |
| 42 | +``` |
| 43 | + |
| 44 | +Output: |
| 45 | + |
| 46 | +| company | classification | |
| 47 | +|----------------------|------------------------| |
| 48 | +| Apple | Information Technology | |
| 49 | +| JPMorgan Chase | Financials | |
| 50 | +| ExxonMobil | Energy | |
| 51 | +| Pfizer | Health Care | |
| 52 | +| Procter & Gamble | Consumer Staples | |
| 53 | +| Tesla | Consumer Discretionary | |
| 54 | +| AT&T | Communication Services | |
| 55 | +| Caterpillar | Industrials | |
| 56 | +| Duke Energy | Utilities | |
| 57 | +| Simon Property Group | Real Estate | |
| 58 | + |
| 59 | +### Binary classification |
| 60 | + |
| 61 | +For yes/no questions, use two categories: |
| 62 | + |
| 63 | +```python |
| 64 | +result = await classify( |
| 65 | + task="Is this company founder-led?", |
| 66 | + categories=["yes", "no"], |
| 67 | + input=companies, |
| 68 | +) |
| 69 | +``` |
| 70 | + |
| 71 | +### Custom output column and reasoning |
| 72 | + |
| 73 | +```python |
| 74 | +result = await classify( |
| 75 | + task="Classify each company by its primary industry sector", |
| 76 | + categories=["Technology", "Finance", "Healthcare", "Energy"], |
| 77 | + input=companies, |
| 78 | + classification_field="sector", |
| 79 | + include_reasoning=True, |
| 80 | +) |
| 81 | +print(result.data[["company", "sector", "reasoning"]]) |
| 82 | +``` |
| 83 | + |
| 84 | +## Parameters |
| 85 | + |
| 86 | +| Name | Type | Default | Description | |
| 87 | +|------|------|---------|-------------| |
| 88 | +| `task` | str | required | Natural-language instructions describing how to classify each row | |
| 89 | +| `categories` | list[str] | required | Allowed category values (minimum 2). Each row is assigned exactly one. | |
| 90 | +| `input` | DataFrame | required | Rows to classify | |
| 91 | +| `classification_field` | str | `"classification"` | Name of the output column for the assigned category | |
| 92 | +| `include_reasoning` | bool | `False` | If True, adds a `reasoning` column with the agent's justification | |
| 93 | +| `session` | Session | Optional, auto-created if omitted | | |
| 94 | + |
| 95 | +## Output |
| 96 | + |
| 97 | +One column is added to each input row (name controlled by `classification_field`): |
| 98 | + |
| 99 | +| Column | Type | Description | |
| 100 | +|--------|------|-------------| |
| 101 | +| `classification` | str | One of the provided `categories` values | |
| 102 | +| `reasoning` | str | Agent's justification (only if `include_reasoning=True`) | |
| 103 | + |
| 104 | +## Via MCP |
| 105 | + |
| 106 | +MCP tool: `everyrow_classify` |
| 107 | + |
| 108 | +| Parameter | Type | Description | |
| 109 | +|-----------|------|-------------| |
| 110 | +| `task` | string | Classification instructions | |
| 111 | +| `categories` | list[string] | Allowed categories (minimum 2) | |
| 112 | +| `classification_field` | string | Output column name (default: `"classification"`) | |
| 113 | +| `include_reasoning` | boolean | Include reasoning column (default: false) | |
0 commit comments