save_extraction_results
Saves structured extraction results to a JSONL file for visualization or further processing. Input extraction data, specify output name and directory, and receive a confirmation with the saved file path.
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_dir | No | . | |
| output_name | Yes |
Input Schema (JSON Schema)
Implementation Reference
- src/langextract_mcp/server.py:403-448 (handler)The handler function decorated with @mcp.tool that implements the save_extraction_results tool. It saves the provided extraction results to a JSONL file in the specified output directory and returns confirmation details.@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)}")