Index of every page on this site: llms.txt
All skills
comet-ml avatar
by Cometcomet-ml/opik23k stars
1,964
Run it yourself

Python SDK patterns for Opik. Use when working in sdks/python, on SDK APIs, integrations, or message processing.

Use this Skill: https://skilld.dev/gh/comet-ml/opik/python-sdk

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

error-handling.md

≈631 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Python SDK Error Handling

Exception Hierarchy

All custom exceptions inherit from OpikException:

from opik.exceptions import (
    OpikException,          # Base for all Opik errors
    ConfigurationError,     # Invalid configuration
    MetricComputationError, # Metric computation failed
    GuardrailValidationFailed,  # Guardrail check failed
    ScoreMethodMissingArguments,  # Score method missing args
    OpikCloudRequestsRateLimited,  # Rate limited
)

MetricComputationError

Always raise MetricComputationError from BaseMetric subclasses instead of hiding errors:

from opik.evaluation.metrics import BaseMetric
from opik.exceptions import MetricComputationError

class MyMetric(BaseMetric):
    def score(self, text: str) -> ScoreResult:
        try:
            # computation logic
            return ScoreResult(value=result)
        except Exception as e:
            # ✅ GOOD - Raise MetricComputationError
            raise MetricComputationError(f"Failed to compute metric: {e}")

            # ❌ BAD - Don't hide errors
            # return ScoreResult(value=0.0)

Structured Exception Information

class ScoreMethodMissingArguments(OpikException):
    def __init__(
        self,
        score_name: str,
        missing_required_arguments: Sequence[str],
        available_keys: Sequence[str],
    ):
        self.score_name = score_name
        self.missing_required_arguments = missing_required_arguments
        self.available_keys = available_keys
        super().__init__(self._get_error_message())

    def _get_error_message(self) -> str:
        return (
            f"The scoring method {self.score_name} is missing arguments: "
            f"{self.missing_required_arguments}. Available keys: {self.available_keys}."
        )

HTTP Error Handling

try:
    response = self._rest_client.call(...)
except rest_api_core.ApiError as e:
    if e.status_code == 409:
        # Conflict - duplicate request, ignore
        return
    elif e.status_code == 429:
        # Rate limited - handle retry
        raise OpikCloudRequestsRateLimited(...)
    else:
        LOGGER.error("API call failed: %s", str(e))
        raise

Best Practices

  • ✅ Use specific exception types
  • ✅ Inherit from OpikException
  • ✅ Include meaningful error messages with context
  • ✅ Handle rate limiting with retries
  • ❌ Don't catch generic Exception without re-raising
  • ❌ Don't hide errors in metric computations

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts8mo4 checks · Risk SAFE
  • Gen Agent Trust Hub8mo

    The skill provides comprehensive documentation and a refactor assistant for the Opik Python SDK by Comet ML. It is safe for its intended development use, though the refactoring assistant's file-editing capabilities introduce a surface for indirect prompt injection when processing untrusted code.

  • Socket8mo

    No alerts

  • Snyk8mo

    Risk: LOW · No issues

  • Runlayer8mo

    5 files scanned · No issues

Signed by skilld at 9b3d88e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 10 months ago

README badge

README badge for comet-ml/opik/python-sdk