```python:inference/enterprise/workflows/enterprise_blocks/sinks/event_writer/v1.py
import requests


def _extract_detail(response: requests.Response) -> str:
    """Try to extract 'detail' from a JSON error response."""
    try:
        # Quickly determine whether the body could be a JSON object:
        # only JSON objects (first non-space char == '{') can meaningfully
        # supply a .get("detail", ...) result. If it's not an object, avoid
        # the expensive response.json() call and return the raw text,
        # which mirrors the original function's fallback behavior.
        text = response.text
        stripped = text.lstrip()
        if not stripped or stripped[0] != "{":
            return text

        obj = response.json()
        # If obj is a mapping-like dict, use .get as originally done.
        if isinstance(obj, dict):
            return str(obj.get("detail", text))
        # If it's not a dict but happens to provide .get, try it safely.
        try:
            return str(obj.get("detail", text))
        except Exception:
            return text
    except Exception:
        return response.text
```