generate_visualization
Create interactive HTML visualizations from extracted data using JSONL files. Highlights entities in context with color coding and hover details, ideal for analyzing large datasets.
Instructions
Generate interactive HTML visualization from extraction results.
Creates an interactive HTML file that shows extracted entities highlighted in their original text context. The visualization is self-contained and can handle thousands of entities with color coding and hover details.
Args: jsonl_file_path: Path to the JSONL file containing extraction results output_html_path: Optional path for the HTML output (default: auto-generated)
Returns: Dictionary with HTML file path and generation details
Raises: ToolError: If visualization generation fails
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| jsonl_file_path | Yes | ||
| output_html_path | No |
Input Schema (JSON Schema)
Implementation Reference
- src/langextract_mcp/server.py:450-502 (handler)The core handler function for the 'generate_visualization' tool. It is decorated with @mcp.tool for registration. Reads extraction results from a JSONL file and generates an interactive HTML visualization using langextract's lx.visualize() function, saving it to an HTML file.@mcp.tool def generate_visualization( jsonl_file_path: str, output_html_path: str | None = None ) -> dict[str, str]: """ Generate interactive HTML visualization from extraction results. Creates an interactive HTML file that shows extracted entities highlighted in their original text context. The visualization is self-contained and can handle thousands of entities with color coding and hover details. Args: jsonl_file_path: Path to the JSONL file containing extraction results output_html_path: Optional path for the HTML output (default: auto-generated) Returns: Dictionary with HTML file path and generation details Raises: ToolError: If visualization generation fails """ try: # Validate input file exists input_path = Path(jsonl_file_path) if not input_path.exists(): raise ToolError(f"Input file not found: {jsonl_file_path}") # Generate visualization using langextract html_content = lx.visualize(str(input_path)) # Determine output path if output_html_path: output_path = Path(output_html_path) else: output_path = input_path.parent / f"{input_path.stem}_visualization.html" # Ensure output directory exists output_path.parent.mkdir(parents=True, exist_ok=True) # Write HTML file with open(output_path, 'w', encoding='utf-8') as f: f.write(html_content) return { "message": "Visualization generated successfully", "html_file_path": str(output_path.absolute()), "file_size_bytes": len(html_content.encode('utf-8')) } except Exception as e: raise ToolError(f"Failed to generate visualization: {str(e)}")