Skip to content

cosmotron_mcp.inference.validate

validate_inference_spec

validate_inference_spec(session_dir: str, spec_path: str) -> dict

Validate an InferenceSpec (schema + SACC file checks); promote a valid draft.

Runs the full validator (check_files=True — SACC exists, per-bin prior counts match the SACC's bins, external-likelihood names resolve). On valid: True the normalised spec is written to inference_spec.json beside the draft (the auditable document of record) and its path is returned as final_path.

Parameters:

Name Type Description Default
session_dir str

Session directory.

required
spec_path str

Path to the spec JSON to validate.

required

Returns:

Type Description
dict

{valid, errors, warnings, n_sampled_params, spec, final_path}. final_path

dict

is the promoted inference_spec.json when valid, else None.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def validate_inference_spec(session_dir: str, spec_path: str) -> dict:
    """Validate an InferenceSpec (schema + SACC file checks); promote a valid draft.

    Runs the full validator (``check_files=True`` — SACC exists, per-bin prior counts
    match the SACC's bins, external-likelihood names resolve). On ``valid: True`` the
    normalised spec is written to ``inference_spec.json`` beside the draft (the auditable
    document of record) and its path is returned as ``final_path``.

    Args:
        session_dir: Session directory.
        spec_path: Path to the spec JSON to validate.

    Returns:
        ``{valid, errors, warnings, n_sampled_params, spec, final_path}``. ``final_path``
        is the promoted ``inference_spec.json`` when valid, else ``None``.
    """
    _require_human_gates(session_dir)
    result = _validate_inference_spec(spec_path, check_files=True)
    final_path = None
    if result.get("valid") and result.get("spec") is not None:
        import json as _json
        final = Path(spec_path).parent / "inference_spec.json"
        final.write_text(_json.dumps(result["spec"], indent=2) + "\n")
        final_path = str(final.resolve())
        _log_tool_call(session_dir, "validate_inference_spec", {"spec_path": spec_path})
    return {**result, "final_path": final_path}