Skip to main content
Glama

Text Extractor

extract_from_text

Extract structured data like emails, URLs, phone numbers, dates, and addresses from raw text to parse documents, emails, or web content into clean formats.

Instructions

Extract structured data from raw text: emails, URLs, phone numbers, dates, currencies, addresses, names, or JSON blocks. Useful for parsing documents, emails, web content, or any unstructured text into clean structured data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe raw text to extract data from
extractorsYesWhich types of data to extract. Choose one or more: emails, urls, phone_numbers, dates, currencies, addresses, names, json_blocks
deduplicateNoRemove duplicate results within each type

Implementation Reference

  • The handler function that performs the extraction logic using the helper `extract` function.
    async function handler(input: Input) {
      const extracted = extract(input.text, input.extractors, input.deduplicate);
    
      const totalFound = Object.values(extracted).reduce((sum, arr) => sum + arr.length, 0);
    
      return {
        extracted,
        summary: {
          totalItemsFound: totalFound,
          byType: Object.fromEntries(Object.entries(extracted).map(([k, v]) => [k, v.length])),
        },
      };
    }
  • The extraction helper function that executes regex matching and post-processing based on requested extractors.
    function extract(text: string, extractors: string[], deduplicate: boolean) {
      const results: Record<string, string[]> = {};
    
      for (const extractor of extractors) {
        const pattern = PATTERNS[extractor];
        if (!pattern) continue;
    
        const matches = text.match(pattern.regex) || [];
        let processed = pattern.postProcess ? matches.map(pattern.postProcess) : matches;
    
        if (deduplicate) {
          processed = [...new Set(processed)];
        }
    
        results[extractor] = processed;
      }
    
      return results;
    }
  • Zod schema definition for input validation of the text-extractor tool.
    const inputSchema = z.object({
      text: z
        .string()
        .min(1)
        .max(10_000)
        .describe("Raw text to extract structured data from"),
      extractors: z
        .array(
          z.enum([
            "emails",
            "urls",
            "phone_numbers",
            "dates",
            "currencies",
            "addresses",
            "names",
            "json_blocks",
          ])
        )
        .min(1)
        .describe("Which types of data to extract"),
      deduplicate: z.boolean().default(true).describe("Remove duplicate results"),
    });
  • Registration of the text-extractor tool within the registry. Note that the registration key used in the server is "extract_from_text" while the internal tool name is "text-extractor".
    const textExtractorTool: ToolDefinition<Input> = {
      name: "text-extractor",
      description:
        "Extract structured data (emails, URLs, phone numbers, dates, currencies, addresses, names, JSON blocks) from raw text. Essential for agents processing unstructured documents, emails, or web content.",
      version: "1.0.0",
      inputSchema,
      handler,
      metadata: {
        tags: ["extraction", "parsing", "nlp", "data-transformation"],
        pricing: "$0.0005 per call",
        exampleInput: {
          text: "Contact John Smith at john@example.com or call (555) 123-4567. Meeting on Jan 15, 2025 at 123 Main St, Springfield, IL 62701. Budget: $5,000.00 USD.",
          extractors: ["emails", "phone_numbers", "dates", "addresses", "currencies"],
          deduplicate: true,
        },
      },
    };
    
    registerTool(textExtractorTool);
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions deduplication indirectly via the parameter reference but does not disclose output format, idempotency, safety characteristics, or behavior when no matches are found—information crucial for an extraction utility with no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences total with zero redundancy. The first sentence front-loads specific capabilities and supported entities; the second sentence provides usage context. Every word serves the selection decision.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the straightforward 3-parameter input with complete schema coverage, the description adequately covers invocation requirements. However, lacking an output schema, it omits description of the return structure (array vs object, match formatting) which would complete the agent's understanding of the tool's contract.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, establishing a baseline of 3. The description lists the eight extractor types (emails, URLs, etc.) but merely echoes the enum values already present in the schema without adding semantic context such as date formats, phone number normalization rules, or name detection heuristics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb ('Extract') and resource ('structured data from raw text'), then enumerates exact entity types supported. It implicitly distinguishes from siblings like 'extract_contract_clauses' and 'extract_meeting_action_items' by emphasizing general 'raw text' and 'unstructured text' rather than specific document domains.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The second sentence provides clear contextual guidance ('Useful for parsing documents, emails, web content...') establishing when to invoke the tool. However, it does not explicitly reference sibling alternatives or state when NOT to use this versus the specialized extraction tools available.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marras0914/agent-toolbelt'

If you have feedback or need assistance with the MCP directory API, please join our Discord server