validate_dashboard_config
Validate Vizro dashboard configurations to ensure proper structure and functionality before deployment. Checks configuration syntax, data references, and custom chart integration for error-free dashboard creation.
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.
Returns:
ValidationResults object with status and dashboard details
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dashboard_config | Yes | Either a JSON string or a dictionary representing a Vizro dashboard model configuration | |
| data_infos | Yes | List of DFMetaData objects containing information about the data files | |
| custom_charts | Yes | List of ChartPlan objects containing information about the custom charts in the dashboard | |
| auto_open | No | Whether to automatically open the PyCafe link in a browser |
Implementation Reference
- The core handler function for the 'validate_dashboard_config' tool. Decorated with @mcp.tool(), it validates the provided dashboard configuration using Vizro's model_validate, handles custom charts, generates Python code and optional PyCafe preview link, and opens the browser if specified.@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()
- Pydantic-style dataclass defining the output schema for the validate_dashboard_config tool (and similar validation tools), including validation status, error/success message, generated Python code, PyCafe URL, and browser open status.@dataclass class ValidateResults: """Results of validation tools.""" valid: bool message: str python_code: str pycafe_url: str | None browser_opened: bool