> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyformat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Email Lead Extraction

> Extract leads from email text using the text input method

Uses the **text input method**, which sends raw email body text directly to the API without a file upload.

## Workflow fields

<Tip>
  We recommend creating this workflow in the [anyformat platform](https://app.anyformat.ai) where you can test with sample emails and iterate on field descriptions. Copy the workflow ID to use with the API.
</Tip>

| Field          | Type          | Description                                   |
| -------------- | ------------- | --------------------------------------------- |
| `sender_name`  | string        | Name of the person who sent the email         |
| `sender_email` | string        | Email address of the sender                   |
| `company_name` | string        | Company or organization the sender represents |
| `inquiry_type` | enum          | Category of the inquiry                       |
| `urgency`      | enum          | How urgent the request seems                  |
| `topics`       | multi\_select | Products or areas mentioned                   |
| `summary`      | string        | Brief summary of the email                    |

## End-to-end

<Tabs>
  <Tab title="curl" icon="terminal">
    ```bash theme={null}
    # 1. Create the workflow
    curl -X POST 'https://api.anyformat.ai/v2/workflows/' \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $ANYFORMAT_API_KEY" \
      -d '{
        "name": "Email Lead Extractor",
        "description": "Triage inbound sales emails into structured leads",
        "nodes": [
          {"id": "parse_1", "type": "parse"},
          {
            "id": "extract_1",
            "type": "extract",
            "extraction_schema": {
              "fields": [
                {"name": "sender_name",  "description": "Full name of the person who sent the email",       "data_type": "string"},
                {"name": "sender_email", "description": "Email address of the sender",                       "data_type": "string"},
                {"name": "company_name", "description": "Company or organization the sender represents",     "data_type": "string"},
                {
                  "name": "inquiry_type",
                  "description": "The primary category of this inquiry",
                  "data_type": "enum",
                  "enum_options": [
                    {"name": "pricing",      "description": "Pricing or cost inquiry"},
                    {"name": "demo_request", "description": "Request for a product demo"},
                    {"name": "support",      "description": "Technical support or help request"},
                    {"name": "partnership",  "description": "Partnership or integration inquiry"},
                    {"name": "other",        "description": "Other inquiry type"}
                  ]
                },
                {
                  "name": "urgency",
                  "description": "How urgent this request appears based on language and deadlines mentioned",
                  "data_type": "enum",
                  "enum_options": [
                    {"name": "low",    "description": "No urgency signals"},
                    {"name": "medium", "description": "Moderate urgency or soft deadline"},
                    {"name": "high",   "description": "Explicit deadline or urgent language"}
                  ]
                },
                {
                  "name": "topics",
                  "description": "Products or areas of interest mentioned in the email",
                  "data_type": "multi_select",
                  "enum_options": [
                    {"name": "product_a",   "description": "Product A"},
                    {"name": "product_b",   "description": "Product B"},
                    {"name": "enterprise",  "description": "Enterprise plan or features"},
                    {"name": "integration", "description": "Integration or API capabilities"},
                    {"name": "pricing",     "description": "Pricing or billing"},
                    {"name": "security",    "description": "Security or compliance"}
                  ]
                },
                {"name": "summary", "description": "A one-sentence summary of what the sender is asking for", "data_type": "string"}
              ]
            }
          }
        ],
        "edges": [{"source": "parse_1", "target": "extract_1"}]
      }'

    # 2. Submit the email body as text (no file upload)
    curl -X POST 'https://api.anyformat.ai/v2/workflows/WORKFLOW_ID/run/' \
      -H "Authorization: Bearer $ANYFORMAT_API_KEY" \
      -H 'Content-Type: application/json' \
      -d '{
        "text": "From: Maria Lopez <maria@acmecorp.com>\nSubject: Enterprise pricing for Q2\n\nHi, I am the VP of Engineering at Acme Corp..."
      }'

    # 3. Poll for results
    curl -H "Authorization: Bearer $ANYFORMAT_API_KEY" \
      'https://api.anyformat.ai/v2/workflows/WORKFLOW_ID/files/COLLECTION_ID/results/'
    ```
  </Tab>

  <Tab title="TypeScript" icon="js" iconType="brands">
    ```typescript theme={null}
    import { Anyformat, Schema } from "@anyformat/sdk";

    const af = new Anyformat({ apiKey: process.env.ANYFORMAT_API_KEY! });

    const emailText = `From: Maria Lopez <maria@acmecorp.com>
    Subject: Enterprise pricing for Q2

    Hi, I am the VP of Engineering at Acme Corp...`;

    // `Workflow.run(null, { text })` submits raw text instead of a file.
    const workflow = await af
      .workflow("Email Lead Extractor", "Triage inbound sales emails into structured leads")
      .parse()
      .extract([
        Schema.string("sender_name",  "Full name of the person who sent the email"),
        Schema.string("sender_email", "Email address of the sender"),
        Schema.string("company_name", "Company or organization the sender represents"),
        Schema.enum("inquiry_type", "The primary category of this inquiry", [
          Schema.option("pricing",      "Pricing or cost inquiry"),
          Schema.option("demo_request", "Request for a product demo"),
          Schema.option("support",      "Technical support or help request"),
          Schema.option("partnership",  "Partnership or integration inquiry"),
          Schema.option("other",        "Other inquiry type"),
        ]),
        Schema.enum("urgency", "How urgent this request appears", [
          Schema.option("low",    "No urgency signals"),
          Schema.option("medium", "Moderate urgency or soft deadline"),
          Schema.option("high",   "Explicit deadline or urgent language"),
        ]),
        Schema.multiSelect("topics", "Products or areas of interest mentioned", [
          Schema.option("product_a",   "Product A"),
          Schema.option("product_b",   "Product B"),
          Schema.option("enterprise",  "Enterprise plan or features"),
          Schema.option("integration", "Integration or API capabilities"),
          Schema.option("pricing",     "Pricing or billing"),
          Schema.option("security",    "Security or compliance"),
        ]),
        Schema.string("summary", "A one-sentence summary of what the sender is asking for"),
      ])
      .create();

    const run = await workflow.run(null, { text: emailText });
    const result = await run.wait();

    if (result.field("urgency")?.value === "high") {
      console.log(`HIGH PRIORITY: ${result.field("sender_name")?.value} from ${result.field("company_name")?.value}`);
    }
    ```
  </Tab>

  <Tab title="Python" icon="python" iconType="brands">
    ```python theme={null}
    import os
    from anyformat.sdk import Client
    from anyformat.workflow import Schema

    client = Client(api_key=os.environ["ANYFORMAT_API_KEY"])

    email_text = """From: Maria Lopez <maria@acmecorp.com>
    Subject: Enterprise pricing for Q2

    Hi, I am the VP of Engineering at Acme Corp..."""

    workflow = (
        client.workflow("Email Lead Extractor")
        .parse()
        .extract([
            Schema.string("sender_name",  "Full name of the person who sent the email"),
            Schema.string("sender_email", "Email address of the sender"),
            Schema.string("company_name", "Company or organization the sender represents"),
            Schema.enum("inquiry_type", "The primary category of this inquiry", options=[
                Schema.option("pricing",      "Pricing or cost inquiry"),
                Schema.option("demo_request", "Request for a product demo"),
                Schema.option("support",      "Technical support or help request"),
                Schema.option("partnership",  "Partnership or integration inquiry"),
                Schema.option("other",        "Other inquiry type"),
            ]),
            Schema.enum("urgency", "How urgent this request appears", options=[
                Schema.option("low",    "No urgency signals"),
                Schema.option("medium", "Moderate urgency or soft deadline"),
                Schema.option("high",   "Explicit deadline or urgent language"),
            ]),
            Schema.multi_select("topics", "Products or areas of interest mentioned", options=[
                Schema.option("product_a",   "Product A"),
                Schema.option("product_b",   "Product B"),
                Schema.option("enterprise",  "Enterprise plan or features"),
                Schema.option("integration", "Integration or API capabilities"),
                Schema.option("pricing",     "Pricing or billing"),
                Schema.option("security",    "Security or compliance"),
            ]),
            Schema.string("summary", "A one-sentence summary of what the sender is asking for"),
        ])
        .create()
    )

    # `Workflow.run(text=...)` submits raw text instead of a file.
    result = workflow.run(text=email_text).wait()

    if result.fields["urgency"].value == "high":
        print(f"HIGH PRIORITY: {result.fields['sender_name'].value} from {result.fields['company_name'].value}")
    ```
  </Tab>
</Tabs>

## Tips

<Note>
  A `string` field like `summary` with a descriptive prompt acts as a mini-summarizer, giving you a one-sentence digest alongside the extracted fields.
</Note>

* Write detailed `enum_options` descriptions to help distinguish between similar categories. "pricing" vs "demo\_request" can be ambiguous without good descriptions.
* `multi_select` captures all relevant topics even when an email discusses several products at once.
* For `.eml` or `.msg` files, use file upload instead — it preserves headers and attachments.

## Next steps

<CardGroup cols={2}>
  <Card title="Run workflow" icon="play" href="/api-reference/workflows/run">
    All input methods: file upload and text
  </Card>

  <Card title="Webhooks" icon="bolt" href="/api-reference/webhooks/overview">
    Use webhooks instead of polling for production email pipelines
  </Card>
</CardGroup>
