"""Tool result helpers."""

from __future__ import annotations

import json


def content_indicates_error(content: str) -> bool:
    """
    Whether tool output represents an error payload.

    Convention: JSON object with a truthy top-level ``error`` field.
    Non-JSON / plain text / ``{"error": null}`` are treated as non-errors.
    """
    try:
        payload = json.loads(content)
    except (TypeError, json.JSONDecodeError):
        return False
    if not isinstance(payload, dict):
        return False
    return bool(payload.get("error"))
