Skip to content

Production scores and feedback

Attach scores and user feedback to production traces.

score_trace

score_trace(metric: LocalMetric, sample: Sample, *, trace_id: str | None = None) -> bool

Run metric on sample now and queue the result for the trace.

Trace: trace_id, else sample.trace_id, else the current trace. A metric whose requires are not met is skipped (False). A raising metric logs a warning and queues label="ERROR" with the exception as explanation (True when that score is queued).

log_score

log_score(name: str, value: float | bool | None, *, trace_id: str | None = None, label: str | None = None, explanation: str | None = None, threshold: float | None = None, metadata: Mapping[str, Any] | None = None) -> bool

Queue a score for a trace (default: the current one). False when not queued.

The platform sets PASS/FAIL with the same rule as experiment metrics: an explicit label FAIL/ERROR/SKIPPED wins, a value under threshold fails, otherwise 0 fails and anything else passes.

log_feedback

log_feedback(positive: bool, *, trace_id: str | None = None, comment: str | None = None, user_id: str | None = None) -> bool

Record an end-user thumbs up/down on a trace (user_feedback, 1 or 0).

One value per (trace, user): a user changing their mind replaces the old value. Without user_id the feedback is anonymous and shares one row per trace (the last write wins).