errors.py 554 B

123456789101112131415161718192021
  1. """Tool result helpers."""
  2. from __future__ import annotations
  3. import json
  4. def content_indicates_error(content: str) -> bool:
  5. """
  6. Whether tool output represents an error payload.
  7. Convention: JSON object with a truthy top-level ``error`` field.
  8. Non-JSON / plain text / ``{"error": null}`` are treated as non-errors.
  9. """
  10. try:
  11. payload = json.loads(content)
  12. except (TypeError, json.JSONDecodeError):
  13. return False
  14. if not isinstance(payload, dict):
  15. return False
  16. return bool(payload.get("error"))