> ## Documentation Index
> Fetch the complete documentation index at: https://ritika-fa61c43f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Enum Reference: All Five CRM Pipeline Strategy Enums

> Reference for all five CRM pipeline enums — PipelineActionType, StandardizationStrategy, MissingStrategy, DeduplicationStrategy, and ConflictRule.

The CRM Data Pipeline environment defines five `str`-based enums that control every aspect of agent behavior. Because all five inherit from both `str` and Python's `Enum`, their values are simultaneously valid Python enum members and plain JSON strings — you can pass either form in your action payloads and Pydantic will accept both. This page documents every enum value, its semantics, the columns or scenarios it applies to, and the reward implications of each choice.

***

## PipelineActionType

`PipelineActionType` is the discriminator field of `CRMPipelineAction`. It defines the eight discrete actions available to the agent and determines which other fields the server reads from the payload.

```python theme={null}
class PipelineActionType(str, Enum):
    VIEW_SOURCE        = "VIEW_SOURCE"
    PROFILE_SOURCE     = "PROFILE_SOURCE"
    STANDARDIZE_COLUMN = "STANDARDIZE_COLUMN"
    HANDLE_MISSING     = "HANDLE_MISSING"
    MERGE_SOURCES      = "MERGE_SOURCES"
    DEDUPLICATE        = "DEDUPLICATE"
    EXECUTE_SQL        = "EXECUTE_SQL"
    SUBMIT_PIPELINE    = "SUBMIT_PIPELINE"
```

| Value | Description | Required Fields |
| - | - | - |
| `VIEW_SOURCE` | Render the top 3 rows of a source as a Markdown table and populate `current_view`. No reward. | `source` |
| `PROFILE_SOURCE` | Generate a per-column type and null-count report; populates `data_quality_report`. Earns `+0.02`. | `source` |
| `STANDARDIZE_COLUMN` | Apply a deterministic transformation to a single column in-place. Reward proportional to rows improved. | `source`, `column`, `standardization_strategy` |
| `HANDLE_MISSING` | Fill or drop rows with null values in a specific column. Reward proportional to nulls resolved. | `source`, `column`, `missing_strategy` |
| `MERGE_SOURCES` | Outer-join two DataFrames on a shared key and write the result to a new named source. Earns `+0.05`. | `source`, `source2`, `join_key`, `output_table` |
| `DEDUPLICATE` | Remove duplicate rows using exact or fuzzy matching. Reward proportional to rows removed. | `source`, `deduplication_strategy` |
| `EXECUTE_SQL` | Execute a read-only `SELECT` query over all registered DataFrames via in-memory SQLite. Earns `+0.10`. | `query`, `output_table` |
| `SUBMIT_PIPELINE` | End the episode; capture `final_source` for grading. Requires ≥ 3 prior steps. Reward = schema match ratio × 0.20. | `final_source` |

> [!TIP]
>
> A productive Task 1 episode typically follows the sequence: `PROFILE_SOURCE` → `STANDARDIZE_COLUMN` (×3-4) → `HANDLE_MISSING` (×2) → `DEDUPLICATE` → `SUBMIT_PIPELINE`. Each transformation step contributes incremental reward before the final grader evaluation.

***

## StandardizationStrategy

`StandardizationStrategy` controls how `STANDARDIZE_COLUMN` mutates a column's values. The server applies the transformation in-place to every row of the target column in `source`.

```python theme={null}
class StandardizationStrategy(str, Enum):
    TO_DATETIME_ISO = "TO_DATETIME_ISO"
    LOWERCASE_STRIP = "LOWERCASE_STRIP"
    EXTRACT_NUMBERS = "EXTRACT_NUMBERS"
    PHONE_E164      = "PHONE_E164"
```

| Value | Transformation Applied | Target Column | Notes |
| - | - | - | - |
| `LOWERCASE_STRIP` | `.lower().strip()` on all string values | `email`, `name` | Use on `email` before deduplication with `EXACT_EMAIL` to ensure case-insensitive matching |
| `TO_DATETIME_ISO` | Parse date strings via `pd.to_datetime(errors='coerce')` → `YYYY-MM-DDTHH:MM:SS`; invalid dates become `""` | `signup_date` | Handles `YYYY/MM/DD`, `MM-DD-YYYY`, and other common formats; invalid months like `2023-13-12` become empty |
| `EXTRACT_NUMBERS` | Strip all non-digit characters; handle `ext.`/`x` extensions; reformat as `+<digits>` | `phone` | Use as a pre-processing step before `PHONE_E164`; removes `(555) 123-4567` → `+15551234567` and strips `ext.` |
| `PHONE_E164` | Direct phone format normalization to `+XXXXXXXXXX` E.164 standard | `phone` | Use after `EXTRACT_NUMBERS` for two-pass phone cleaning, or standalone if data is already mostly numeric |

### Column-to-Strategy Mapping for Task 1

The Task 1 schema target maps directly to these strategies:

```python theme={null}
# Schema target:
# "email": "string (lowercase, stripped)"  → LOWERCASE_STRIP
# "name":  "string (stripped)"             → LOWERCASE_STRIP
# "signup_date": "string ISO 8601 or empty" → TO_DATETIME_ISO
# "phone": "string E.164 format (+1...) or empty" → EXTRACT_NUMBERS then verify

from models import CRMPipelineAction, PipelineActionType, StandardizationStrategy

# Email standardization
CRMPipelineAction(
    action_type=PipelineActionType.STANDARDIZE_COLUMN,
    source="web_forms",
    column="email",
    standardization_strategy=StandardizationStrategy.LOWERCASE_STRIP
)

# Date standardization
CRMPipelineAction(
    action_type=PipelineActionType.STANDARDIZE_COLUMN,
    source="web_forms",
    column="signup_date",
    standardization_strategy=StandardizationStrategy.TO_DATETIME_ISO
)

# Phone pre-processing — strips extensions, parentheses, dashes
CRMPipelineAction(
    action_type=PipelineActionType.STANDARDIZE_COLUMN,
    source="web_forms",
    column="phone",
    standardization_strategy=StandardizationStrategy.EXTRACT_NUMBERS
)
```

> [!WARNING]
>
> The data generator injects phone values like `"(555) 123-4567"`, `"15551234567 ext. 42"`, and `"Invalid Number"`. `EXTRACT_NUMBERS` handles the first two but cannot recover the third — follow up with `HANDLE_MISSING` using `FILL_VALUE` and `fallback_value=""` to replace any remaining non-numeric residuals.

***

## MissingStrategy

`MissingStrategy` controls how `HANDLE_MISSING` resolves `null` / `NaN` values in a specific column. The strategy is applied in-place; the source DataFrame is mutated within the episode's memory.

```python theme={null}
class MissingStrategy(str, Enum):
    FILL_MEAN  = "FILL_MEAN"
    FILL_MODE  = "FILL_MODE"
    FILL_VALUE = "FILL_VALUE"
    DROP_ROW   = "DROP_ROW"
```

| Value | Behavior | Reward Formula | Use Case |
| - | - | - | - |
| `FILL_MEAN` | Replace nulls with the arithmetic mean of the column | Proportional to nulls resolved × 0.10 | Numeric columns (not applicable to CRM schema columns which are all strings) |
| `FILL_MODE` | Replace nulls with the most frequent non-null value in the column | Proportional to nulls resolved × 0.10 | Categorical string columns where a dominant value exists |
| `FILL_VALUE` | Replace every null with the literal string in `fallback_value` | Proportional to nulls resolved × 0.05 | Any column — use `""` for `phone`/`signup_date` to produce the "empty string" format the grader expects |
| `DROP_ROW` | Drop every row where the specified column is null | Proportional to rows dropped / original rows × 0.10 | Use on `email` when deduplication requires non-null keys |

### Strategy Selection Guide

```python theme={null}
from models import CRMPipelineAction, PipelineActionType, MissingStrategy

# Fill missing phone with empty string (grader-compliant format)
CRMPipelineAction(
    action_type=PipelineActionType.HANDLE_MISSING,
    source="web_forms",
    column="phone",
    missing_strategy=MissingStrategy.FILL_VALUE,
    fallback_value=""
)

# Fill missing signup_date with empty string
CRMPipelineAction(
    action_type=PipelineActionType.HANDLE_MISSING,
    source="web_forms",
    column="signup_date",
    missing_strategy=MissingStrategy.FILL_VALUE,
    fallback_value=""
)

# Drop rows with null email before EXACT_EMAIL deduplication
CRMPipelineAction(
    action_type=PipelineActionType.HANDLE_MISSING,
    source="web_forms",
    column="email",
    missing_strategy=MissingStrategy.DROP_ROW
)
```

> [!NOTE]
>
> For the CRM schema, `FILL_VALUE` with `fallback_value=""` is the correct strategy for `phone` and `signup_date`. The grader compares your output against the ground truth using `.fillna("").astype(str).str.strip().str.lower()`, so an empty string matches the truth's empty string exactly. Using `FILL_MODE` on `phone` would fill nulls with the most common phone number, which would not match the truth.

***

## DeduplicationStrategy

`DeduplicationStrategy` controls the matching heuristic used by `DEDUPLICATE` to identify and remove redundant rows from a source DataFrame.

```python theme={null}
class DeduplicationStrategy(str, Enum):
    FUZZY_NAME_PHONE = "FUZZY_NAME_PHONE"
    EXACT_EMAIL      = "EXACT_EMAIL"
```

| Value | Matching Logic | Best For | Prerequisite |
| - | - | - | - |
| `EXACT_EMAIL` | `drop_duplicates(subset=["email"])` — exact string equality on the `email` column | Removing exact duplicate records after email standardization | Run `STANDARDIZE_COLUMN` with `LOWERCASE_STRIP` on `email` first; otherwise `"John@Example.com"` and `"john@example.com"` count as different rows |
| `FUZZY_NAME_PHONE` | Lowercased+stripped `name` and digit-extracted `phone` are paired as a composite key; `drop_duplicates` on that pair | Catching near-duplicate entries where the email is missing or differs (e.g., nicknames with the same phone) | Works on pre-standardization data but is more accurate after `LOWERCASE_STRIP` on `name` and `EXTRACT_NUMBERS` on `phone` |

### Reward Calculation

Both strategies earn reward proportional to the fraction of rows removed:

```
reward = (rows_removed / original_row_count) × 0.20
```

If 12 duplicates are removed from a 60-row source, the reward is `(12 / 60) × 0.20 = 0.04`.

### Usage Examples

```python theme={null}
from models import CRMPipelineAction, PipelineActionType, DeduplicationStrategy, StandardizationStrategy

# Recommended Task 1 approach: standardize email first, then dedup
# Step 1: Normalize email case
CRMPipelineAction(
    action_type=PipelineActionType.STANDARDIZE_COLUMN,
    source="web_forms",
    column="email",
    standardization_strategy=StandardizationStrategy.LOWERCASE_STRIP
)

# Step 2: Deduplicate by exact email match
CRMPipelineAction(
    action_type=PipelineActionType.DEDUPLICATE,
    source="web_forms",
    deduplication_strategy=DeduplicationStrategy.EXACT_EMAIL
)

# Alternative: fuzzy match before standardization to catch name-based duplicates
CRMPipelineAction(
    action_type=PipelineActionType.DEDUPLICATE,
    source="web_forms",
    deduplication_strategy=DeduplicationStrategy.FUZZY_NAME_PHONE
)
```

> [!TIP]
>
> The data generator (`data_generator.py`) deliberately injects duplicate rows with missing `email` fields and slightly varied names (e.g., `"John Smith"` → `"Mike Smith"` with the same phone). Running `FUZZY_NAME_PHONE` first catches these near-duplicates before `EXACT_EMAIL` cleans up the remaining identical records.

***

## ConflictRule

`ConflictRule` controls how `MERGE_SOURCES` resolves column value conflicts when the same non-key column exists in both source DataFrames. After an outer join, Pandas creates `<column>_s1` and `<column>_s2` suffix pairs; the conflict rule determines how they are collapsed back into a single `<column>`.

```python theme={null}
class ConflictRule(str, Enum):
    PREFER_S1 = "PREFER_S1"
    PREFER_S2 = "PREFER_S2"
    COALESCE  = "COALESCE"
```

| Value | Behavior | Implementation |
| - | - | - |
| `PREFER_S1` | Take the value from `source` (first source); fall back to `source2` only if `source` is null | `s1_col.combine_first(s2_col)` |
| `PREFER_S2` | Take the value from `source2` (second source); fall back to `source` only if `source2` is null | `s2_col.combine_first(s1_col)` |
| `COALESCE` | Take the first non-null value from either source regardless of order (default behavior when `conflict_rule` is omitted) | `s1_col.combine_first(s2_col)` (same as PREFER\_S1 — first non-null wins) |

### Task 3 Column-to-Rule Mapping

In Task 3, the observation's `conflict_rules` field provides explicit per-column instructions. Map those string labels to `ConflictRule` values:

```python theme={null}
# obs.conflict_rules for Task 3:
# {
#   "email":       "prefer_salesforce",   → PREFER_S1 (salesforce is source)
#   "phone":       "prefer_web_leads",    → PREFER_S2 (web_leads is source2)
#   "customer_id": "prefer_salesforce"    → PREFER_S1
# }

from models import CRMPipelineAction, PipelineActionType, ConflictRule

# Merge salesforce + web_leads, preferring web_leads phone data
CRMPipelineAction(
    action_type=PipelineActionType.MERGE_SOURCES,
    source="salesforce",      # s1 — canonical email, customer_id
    source2="web_leads",      # s2 — fresher phone data
    join_key="email",
    conflict_rule=ConflictRule.PREFER_S2,   # phone: prefer_web_leads
    output_table="sf_wl_merged"
)
```

> [!WARNING]
>
> `ConflictRule` is a single value applied uniformly to all conflicting columns in a merge. If Task 3 requires `PREFER_S1` for `email` but `PREFER_S2` for `phone`, you cannot express both in one `MERGE_SOURCES` call. Use `EXECUTE_SQL` after merging with `COALESCE` to apply per-column overrides:
>
> ```python theme={null}
> # After merging with COALESCE, override phone to prefer web_leads value
> CRMPipelineAction(
>     action_type=PipelineActionType.EXECUTE_SQL,
>     query="""
>         SELECT
>             COALESCE(sf.customer_id, wl.customer_id) AS customer_id,
>             sf.email,
>             COALESCE(wl.phone, sf.phone) AS phone
>         FROM salesforce sf
>         LEFT JOIN web_leads wl ON sf.email = wl.email
>     """,
>     output_table="merged_output"
> )
> ```

***

## Python Import Reference

```python theme={null}
from models import (
    PipelineActionType,
    StandardizationStrategy,
    MissingStrategy,
    DeduplicationStrategy,
    ConflictRule,
)

# All five enums are str subclasses — enum member and raw string are interchangeable
action_type = PipelineActionType.STANDARDIZE_COLUMN
# equivalent to:
action_type = "STANDARDIZE_COLUMN"

# Pydantic accepts both forms in action payloads:
from models import CRMPipelineAction

CRMPipelineAction(
    action_type=PipelineActionType.HANDLE_MISSING,   # enum member
    source="web_forms",
    column="phone",
    missing_strategy="FILL_VALUE",                   # raw string — also valid
    fallback_value=""
)
```

***

## JSON Enum Values

Because all enums inherit from `str`, their serialized form is the raw string value. No special encoding or wrapping is applied:

```json theme={null}
{
  "action_type": "STANDARDIZE_COLUMN",
  "source": "web_forms",
  "column": "email",
  "standardization_strategy": "LOWERCASE_STRIP"
}
```

```json theme={null}
{
  "action_type": "HANDLE_MISSING",
  "source": "web_forms",
  "column": "phone",
  "missing_strategy": "FILL_VALUE",
  "fallback_value": ""
}
```

```json theme={null}
{
  "action_type": "MERGE_SOURCES",
  "source": "salesforce",
  "source2": "web_leads",
  "join_key": "email",
  "conflict_rule": "PREFER_S2",
  "output_table": "merged_output"
}
```

```json theme={null}
{
  "action_type": "DEDUPLICATE",
  "source": "web_forms",
  "deduplication_strategy": "EXACT_EMAIL"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.