Always use safe access methods when working with potentially null or undefined values. Use .get() for dictionary access, check array bounds before indexing, and validate existence before operations.

Key patterns to follow:

Example of safe patterns:

# Safe dictionary access
description = tool.get("description")  # Instead of tool["description"]
api_key = deployment.get("litellm_params", {}).get("api_key")

# Safe array access  
if len(results) > 0 and results[0].get("moderations"):
    # Process moderations

# Proper null checking logic
if all([batch_cost is not None, batch_usage is not None, batch_models is not None]):
    # Process batch data

# Safe fallback with explicit None check
_deployment_tpm = _deployment.get("tpm")
if _deployment_tpm is None:
    _deployment_tpm = _deployment.get("litellm_params", {}).get("tpm")
if _deployment_tpm is None:
    _deployment_tpm = float("inf")

This prevents KeyError exceptions, IndexError exceptions, and unexpected behavior from falsy values being treated as None.