validate_dashboard_config
Validate Vizro dashboard configurations by checking JSON or dictionary inputs for accuracy. Generate Python code, provide PyCafe links for remote files, and confirm data and custom chart details for proper dashboard functionality.
Instructions
Validate Vizro model configuration. Run ALWAYS when you have a complete dashboard configuration.
If successful, the tool will return the python code and, if it is a remote file, the py.cafe link to the chart.
The PyCafe link will be automatically opened in your default browser if auto_open is True.
Args:
dashboard_config: Either a JSON string or a dictionary representing a Vizro dashboard model configuration
data_infos: List of DFMetaData objects containing information about the data files
custom_charts: List of ChartPlan objects containing information about the custom charts in the dashboard
auto_open: Whether to automatically open the PyCafe link in a browser
Returns:
ValidationResults object with status and dashboard details
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| auto_open | No | ||
| custom_charts | Yes | ||
| dashboard_config | Yes | ||
| data_infos | Yes |
Implementation Reference
- The primary handler function for the 'validate_dashboard_config' tool. It validates the provided dashboard configuration using Vizro's Dashboard.model_validate, handles custom charts, generates Python code for the dashboard, creates a PyCafe preview URL if applicable, and optionally opens it in the browser.@mcp.tool() def validate_dashboard_config( dashboard_config: dict[str, Any] = Field( description="Either a JSON string or a dictionary representing a Vizro dashboard model configuration" ), data_infos: list[DFMetaData] = Field( description="List of DFMetaData objects containing information about the data files" ), custom_charts: list[ChartPlan] = Field( description="List of ChartPlan objects containing information about the custom charts in the dashboard" ), auto_open: bool = Field(default=True, description="Whether to automatically open the PyCafe link in a browser"), ) -> ValidateResults: """Validate Vizro model configuration. Run ALWAYS when you have a complete dashboard configuration. If successful, the tool will return the python code and, if it is a remote file, the py.cafe link to the chart. The PyCafe link will be automatically opened in your default browser if auto_open is True. Returns: ValidationResults object with status and dashboard details """ Vizro._reset() try: dashboard = vm.Dashboard.model_validate( dashboard_config, context={"allow_undefined_captured_callable": [custom_chart.chart_name for custom_chart in custom_charts]}, ) except ValidationError as e: return ValidateResults( valid=False, message=f"""Validation Error: {e!s}. Fix the error and call this tool again. Calling `get_model_json_schema` may help.""", python_code="", pycafe_url=None, browser_opened=False, ) else: code_link = get_python_code_and_preview_link(dashboard, data_infos, custom_charts) pycafe_url = code_link.pycafe_url if all(info.file_location_type == "remote" for info in data_infos) else None browser_opened = False if pycafe_url and auto_open: try: browser_opened = webbrowser.open(pycafe_url) except Exception: browser_opened = False return ValidateResults( valid=True, message="""Configuration is valid for Dashboard! Do not forget to call this tool again after each iteration. If you are creating an `app.py` file, you MUST use the code from the validation tool, do not modify it, watch out for differences to previous `app.py`""", python_code=code_link.python_code, pycafe_url=pycafe_url, browser_opened=browser_opened, ) finally: Vizro._reset()
- Dataclass defining the output schema for the validate_dashboard_config tool, including validation status, message, generated Python code, PyCafe URL, and browser status.@dataclass class ValidateResults: """Results of validation tools.""" valid: bool message: str python_code: str pycafe_url: str | None browser_opened: bool
- vizro-mcp/src/vizro_mcp/server.py:245-245 (registration)Registration of the validate_dashboard_config tool using the @mcp.tool() decorator.@mcp.tool()