Skip to main content
Glama
larsenweigle

LangExtract MCP Server

by larsenweigle

save_extraction_results

Save structured data extraction results to a JSONL file for storage, visualization, or further processing.

Instructions

Save extraction results to a JSONL file for later use or visualization.

Saves the extraction results in JSONL (JSON Lines) format, which is commonly used for structured data and can be loaded for visualization or further processing.

Args: extraction_results: Results from extract_from_text or extract_from_url output_name: Name for the output file (without .jsonl extension) output_dir: Directory to save the file (default: current directory)

Returns: Dictionary with file path and save confirmation

Raises: ToolError: If save operation fails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
extraction_resultsYes
output_nameYes
output_dirNo.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'save_extraction_results' tool. It saves the provided extraction results dictionary to a JSONL file in the specified output directory, creating the directory if necessary. Returns a confirmation dictionary with the file path and extraction count. The @mcp.tool decorator registers this function as an MCP tool, defining its schema from the function signature.
    @mcp.tool  
    def save_extraction_results(
        extraction_results: dict[str, Any],
        output_name: str,
        output_dir: str = "."
    ) -> dict[str, str]:
        """
        Save extraction results to a JSONL file for later use or visualization.
        
        Saves the extraction results in JSONL (JSON Lines) format, which is commonly
        used for structured data and can be loaded for visualization or further processing.
        
        Args:
            extraction_results: Results from extract_from_text or extract_from_url
            output_name: Name for the output file (without .jsonl extension)
            output_dir: Directory to save the file (default: current directory)
            
        Returns:
            Dictionary with file path and save confirmation
            
        Raises:
            ToolError: If save operation fails
        """
        try:
            # Create output directory if it doesn't exist
            output_path = Path(output_dir)
            output_path.mkdir(parents=True, exist_ok=True)
            
            # Create full file path
            file_path = output_path / f"{output_name}.jsonl"
            
            # Save results to JSONL format
            import json
            with open(file_path, 'w', encoding='utf-8') as f:
                json.dump(extraction_results, f, ensure_ascii=False)
                f.write('\n')
            
            return {
                "message": "Results saved successfully",
                "file_path": str(file_path.absolute()),
                "total_extractions": extraction_results.get("total_extractions", 0)
            }
            
        except Exception as e:
            raise ToolError(f"Failed to save results: {str(e)}")
  • The @mcp.tool decorator registers the save_extraction_results function as an MCP tool.
    @mcp.tool  
  • The function signature defines the input schema (extraction_results: dict, output_name: str, output_dir: str) and output type (dict[str, str]) for the tool, handled by Pydantic in FastMCP.
    def save_extraction_results(
        extraction_results: dict[str, Any],
        output_name: str,
        output_dir: str = "."
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool saves to a file, returns a dictionary with file path and confirmation, and raises ToolError on failure. However, it lacks details on permissions needed, file overwriting behavior, or rate limits. The description does not contradict annotations (none provided).

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

Conciseness4/5

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

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by supporting details. The Args and Returns sections are structured but slightly verbose; every sentence adds value, though some redundancy exists (e.g., repeating JSONL format).

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 3 parameters with 0% schema coverage, no annotations, and an output schema (implied by Returns), the description is fairly complete. It explains parameters, return values, and errors, but could improve by detailing file naming conventions or visualization integration. The output schema reduces the need to fully explain returns.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaning beyond the schema by explaining extraction_results comes from specific sibling tools, output_name excludes the .jsonl extension, and output_dir defaults to current directory. This covers all 3 parameters, though it could provide more detail on format or constraints.

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 clearly states the specific action ('Save extraction results') and resource ('to a JSONL file'), distinguishing it from sibling tools like extract_from_text, extract_from_url, and generate_visualization. It explicitly mentions the format (JSONL) and purpose (for later use or visualization), avoiding tautology with the tool name.

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 description provides clear context on when to use this tool: after extraction from text or URL, for saving results to a file. It implies usage by referencing sibling tools (extract_from_text, extract_from_url) as sources for the extraction_results parameter. However, it does not explicitly state when not to use it or name alternatives (e.g., vs. generate_visualization).

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/larsenweigle/langextract-mcp'

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