-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
140 lines (110 loc) · 4.36 KB
/
Copy patherrors.py
File metadata and controls
140 lines (110 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"""Error categories for the prompt-management capability."""
from __future__ import annotations
from typing import Any, ClassVar
PROMPT_NOT_FOUND = "prompt_not_found"
PROMPT_RENDER_ERROR = "prompt_render_error"
PROMPT_STORE_UNAVAILABLE = "prompt_store_unavailable"
PROMPT_GROUP_INVALID = "prompt_group_invalid"
# Mirrors openarmature.llm.errors.TRANSIENT_CATEGORIES. Retry-middleware
# classifiers MAY import this to identify transient prompt-management
# failures by category.
PROMPT_TRANSIENT_CATEGORIES: frozenset[str] = frozenset({PROMPT_STORE_UNAVAILABLE})
class PromptError(Exception):
"""Base for prompt-management errors. Subclasses set ``category``
to one of the canonical identifier strings."""
category: ClassVar[str]
class PromptNotFound(PromptError):
"""Raised when no prompt matches ``(name, label)``.
Non-transient: retrying the same name + label will not succeed
without changing the backends or the prompt store contents.
"""
category = PROMPT_NOT_FOUND
name: str
label: str
backend: str | None
def __init__(
self,
*args: Any,
name: str,
label: str,
backend: str | None = None,
) -> None:
super().__init__(*args)
self.name = name
self.label = label
self.backend = backend
class PromptRenderError(PromptError):
"""Raised when render fails: undefined variable under strict
handling, template parse error, or variable-coercion failure.
Carries the source prompt's identity plus the variable mapping
and a description of the render failure.
Non-transient: retrying the same render with the same prompt +
variables will not succeed. Callers whose backend
serves a fixed template later should re-fetch + re-render rather
than relying on retry-middleware to auto-retry the failed render.
"""
category = PROMPT_RENDER_ERROR
# v1 policy on ``variables``: pass-through unchanged (no automatic
# redaction). Callers wanting redaction wrap their variables
# before passing to render. Keys MUST be preserved if a future
# redaction policy lands; only values may be redacted.
name: str
version: str
label: str
variables: dict[str, Any]
description: str
def __init__(
self,
*args: Any,
name: str,
version: str,
label: str,
variables: dict[str, Any],
description: str,
) -> None:
super().__init__(*args)
self.name = name
self.version = version
self.label = label
self.variables = variables
self.description = description
class PromptStoreUnavailable(PromptError):
"""Raised when backend infrastructure fails: network unreachable,
filesystem I/O error, vendor API 5xx, vendor API timeout.
Transient: the same fetch may succeed when the backend recovers.
``PromptManager.fetch`` raises this only after ALL composed
backends raise it; in that aggregate case ``backends_tried``
lists the backends consulted (in order) and ``causes`` carries
the per-backend exceptions index-aligned to ``backends_tried``
so operators can distinguish "backend A 503 + backend B 503"
from "backend A 503 + backend B OSError". The ``__cause__`` chain
still points at the last unavailable for stack-trace continuity.
"""
category = PROMPT_STORE_UNAVAILABLE
name: str | None
label: str | None
backends_tried: list[str] | None
causes: list[BaseException] | None
def __init__(
self,
*args: Any,
name: str | None = None,
label: str | None = None,
backends_tried: list[str] | None = None,
causes: list[BaseException] | None = None,
) -> None:
super().__init__(*args)
self.name = name
self.label = label
self.backends_tried = backends_tried
self.causes = causes
class PromptGroupInvalid(PromptError):
"""Raised when a ``PromptGroup`` construction violates a
group-validity rule. Currently raised when ``members`` contains
fewer than two elements (an empty or single-member group). Raised
at construction time, before any render or LLM call, so an invalid
group never reaches observability emission.
Non-transient: a caller-contract violation. Constructing again with
the same members will not succeed without changing them.
"""
category = PROMPT_GROUP_INVALID