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

# Field Cleaning

> Clean and normalize person fields (email, phone, name, state, country, social URL) and company fields (domain, company name, LinkedIn URL, ticker symbol) to match API format before using search.

## Supported Fields

### Person Fields

| Field        | What It Does                                                                             |
| ------------ | ---------------------------------------------------------------------------------------- |
| `email`      | Removes plus tags, normalizes Gmail dots, lowercases                                     |
| `phone`      | Normalizes to E.164 format (e.g., `+15551234567`)                                        |
| `full_name`  | Strips prefixes/suffixes, normalizes whitespace                                          |
| `first_name` | Strips prefixes, normalizes whitespace                                                   |
| `last_name`  | Strips suffixes, normalizes whitespace                                                   |
| `state`      | Returns full name and code (e.g., `CA` → `{"full_name": "california", "code": "CA"}`)    |
| `country`    | Returns full name and code (e.g., `US` → `{"full_name": "united states", "code": "US"}`) |
| `social_url` | Normalizes LinkedIn, Twitter/X, GitHub, Facebook URLs                                    |
| `school`     | Accepts name, website URL, or domain — detects type and normalizes                       |

### Company Fields

| Field                  | What It Does                                                       |
| ---------------------- | ------------------------------------------------------------------ |
| `domain`               | Extracts domain from URL, removes `www.` prefix                    |
| `company`              | Accepts name, website URL, or domain — detects type and normalizes |
| `linkedin_company_url` | Normalizes LinkedIn company page URL                               |
| `ticker_symbol`        | Uppercases and strips whitespace                                   |

<Note>
  The enrichment endpoints automatically clean inputs before matching. Use this endpoint to clean data before sending to search endpoints, which expect pre-normalized values.
</Note>


## OpenAPI

````yaml POST /utility/clean
openapi: 3.1.0
info:
  title: Data Legion API
  description: API for enriching, searching, and discovering person and company data
  version: 1.0.0
servers:
  - url: https://api.datalegion.ai
security:
  - APIKeyHeader: []
paths:
  /utility/clean:
    post:
      tags:
        - utility
      summary: Clean and normalize fields
      description: >-
        Clean and normalize one or more fields to match API format. Supports
        person fields (email, phone, full_name, first_name, last_name, state,
        country, social_url, school) and company fields (company, domain,
        linkedin_company_url, ticker_symbol). Rate limited to 100 requests per
        minute.
      operationId: clean_fields_utility_clean_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FieldCleanRequest'
        required: true
      responses:
        '200':
          description: Success - fields cleaned and normalized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FieldCleanResponse'
              example:
                results:
                  email:
                    original: John.Doe+tag@gmail.com
                    cleaned: johndoe@gmail.com
                    normalized: true
                  phone:
                    original: (555) 123-4567
                    cleaned: '+15551234567'
                    normalized: true
                  domain:
                    original: https://www.Google.com/about
                    cleaned: google.com
                    normalized: true
                  company:
                    original: Google LLC
                    cleaned:
                      name: google
                      type: name
                    normalized: true
        '400':
          description: Bad request - invalid field or value
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: Payment required - insufficient credits or expired contract
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden - API key not authorized for this endpoint
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    FieldCleanRequest:
      properties:
        fields:
          additionalProperties:
            type: string
          type: object
          minProperties: 1
          title: Fields
          description: >-
            Map of field names to values to clean (e.g., {'email':
            'John.Doe+tag@gmail.com', 'domain':
            'https://www.Google.com/about'}). Supported person fields: email,
            phone, full_name, first_name, last_name, state, country, social_url,
            school. Supported company fields: company, domain,
            linkedin_company_url, ticker_symbol.
        default_region:
          type: string
          title: Default Region
          description: >-
            Default region for phone number normalization (ISO 3166-1 alpha-2
            code)
          default: US
      type: object
      required:
        - fields
      title: FieldCleanRequest
      description: Request model for batch field cleaning.
      example:
        fields:
          email: John.Doe+tag@gmail.com
          phone: (555) 123-4567
          domain: https://www.Google.com/about
          company: Google LLC
    FieldCleanResponse:
      properties:
        results:
          additionalProperties:
            $ref: '#/components/schemas/FieldCleanResult'
          type: object
          title: Results
          description: Map of field names to cleaning results
      type: object
      required:
        - results
      title: FieldCleanResponse
      description: Response model for batch field cleaning.
    ErrorResponse:
      properties:
        error:
          type: string
          title: Error
          description: Error type/code
        message:
          type: string
          title: Message
          description: Human-readable error message
        details:
          anyOf:
            - additionalProperties: true
              type: object
            - items: {}
              type: array
            - type: 'null'
          title: Details
          description: Additional error details (for validation errors)
      type: object
      required:
        - error
        - message
      title: ErrorResponse
      description: Error response model for customer-facing API.
    FieldCleanResult:
      properties:
        original:
          type: string
          title: Original
          description: Original input value
        cleaned:
          anyOf:
            - type: string
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cleaned
          description: Cleaned/normalized value
        normalized:
          type: boolean
          title: Normalized
          description: Whether normalization was applied
      type: object
      required:
        - original
        - cleaned
        - normalized
      title: FieldCleanResult
      description: Result for a single cleaned field.
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: API-Key

````