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
| Name | Required | Description | Default |
|---|---|---|---|
| extraction_results | Yes | ||
| output_name | Yes | ||
| output_dir | No | . |
Implementation Reference
- src/langextract_mcp/server.py:403-448 (handler)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)}")
- src/langextract_mcp/server.py:403-403 (registration)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 = "."