def _verify_cached_simulation_results(
        request: NodeIdAndDatasets,
        simulation_results: Any,
    ) -> None:
        """Verifies the type and id of the cached simulation results."""
        if not isinstance(simulation_results, NeuronSimulationResults) and not isinstance(
            simulation_results, AttentionSimulationResults
        ):
            raise HTTPException(
                status_code=422, detail=f"Unexpected type {type(simulation_results)} in cache"
            )

        elem_id = (
            simulation_results.neuron_id
            if isinstance(simulation_results, NeuronSimulationResults)
            else simulation_results.attention_head_id
        )
        if (
            elem_id.layer_index != request.layer_index
            or elem_id.neuron_index != request.activation_index
        ):
            raise HTTPException(
                status_code=422,
                detail=f"Cache id mismatch: requested ({request.layer_index}, {request.activation_index}, cache contained ({elem_id.layer_index}, {elem_id.layer_index})",
            )
Verifies the type and id of the cached simulation results.
neuron_explainer/activation_server/explainer_routes.py