from typing import Dict, Any def normalize_response(provider: str, response: Dict[str, Any]) -> Dict[str, Any]: normalized = response.copy() # Ensure consistent field names if "result" in normalized and normalized["result"] is None: # Some providers return null, others omit the field pass # Handle null vs missing fields consistently if "error" in normalized and normalized["error"] is None: del normalized["error"] return normalized def normalize_error(error: Exception, error_id: str) -> Dict[str, Any]: return { "jsonrpc": "2.0", "id": 1, "error": { "code": -32603, "message": str(error), "data": {"error_id": error_id} } }