|
1 | 1 | from datetime import datetime |
2 | 2 | from enum import Enum |
3 | | -from typing import TYPE_CHECKING, Any, Literal, Optional |
| 3 | +from typing import TYPE_CHECKING, Any, Literal, NotRequired, Optional, TypedDict |
4 | 4 | from uuid import UUID |
5 | 5 |
|
6 | 6 | from pydantic import BaseModel, Field, HttpUrl |
@@ -629,3 +629,57 @@ class PromptRecommendationJobPublic(SQLModel): |
629 | 629 | recommendation_type: Literal["prompt"] = "prompt" |
630 | 630 | config_version: ConfigVersionPublic | None = None |
631 | 631 | error_message: str | None = None |
| 632 | + |
| 633 | + |
| 634 | +class TraceScore(TypedDict): |
| 635 | + """A score attached to a trace.""" |
| 636 | + |
| 637 | + name: str |
| 638 | + value: float | str |
| 639 | + data_type: str |
| 640 | + comment: NotRequired[str] |
| 641 | + verdict: NotRequired[str] |
| 642 | + # True for placeholder scores on unscoreable items; excluded from summary stats. |
| 643 | + unscoreable: NotRequired[bool] |
| 644 | + |
| 645 | + |
| 646 | +class TraceData(TypedDict): |
| 647 | + """Data for a single trace including Q&A and scores.""" |
| 648 | + |
| 649 | + trace_id: str |
| 650 | + question: str |
| 651 | + llm_answer: str |
| 652 | + question_id: int | None |
| 653 | + ground_truth_answer: str |
| 654 | + category: NotRequired[str] |
| 655 | + # "blocked: ..." | "rephrased" | "applied"; None if guardrails didn't fire. |
| 656 | + guardrail: NotRequired[str | None] |
| 657 | + # LLM input after input guardrails / output before output guardrails. |
| 658 | + input_to_llm: NotRequired[str | None] |
| 659 | + output_from_llm: NotRequired[str | None] |
| 660 | + scores: list[TraceScore] |
| 661 | + |
| 662 | + |
| 663 | +class TraceScoreSummary(TypedDict): |
| 664 | + """A TraceScore without the UI-only fields (data_type, verdict).""" |
| 665 | + |
| 666 | + name: str |
| 667 | + value: float | str |
| 668 | + comment: NotRequired[str] |
| 669 | + unscoreable: NotRequired[bool] |
| 670 | + |
| 671 | + |
| 672 | +class TraceAttempt(TypedDict): |
| 673 | + """One run of a question: its answer and scores.""" |
| 674 | + |
| 675 | + llm_answer: str |
| 676 | + scores: list[TraceScoreSummary] |
| 677 | + |
| 678 | + |
| 679 | +class TraceQuestion(TypedDict): |
| 680 | + """A dataset question with one attempt per duplication-factor repeat.""" |
| 681 | + |
| 682 | + question_id: int | str | None |
| 683 | + question: str |
| 684 | + ground_truth_answer: str |
| 685 | + attempts: list[TraceAttempt] |
0 commit comments