confgate 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- confgate/__init__.py +8 -0
- confgate/_core.py +55 -0
- confgate/_exceptions.py +9 -0
- confgate/_gate.py +46 -0
- confgate-0.1.0.dist-info/METADATA +54 -0
- confgate-0.1.0.dist-info/RECORD +9 -0
- confgate-0.1.0.dist-info/WHEEL +5 -0
- confgate-0.1.0.dist-info/licenses/LICENSE +21 -0
- confgate-0.1.0.dist-info/top_level.txt +1 -0
confgate/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""confgate — confidence-gated decisions for LLM agent outputs."""
|
|
2
|
+
|
|
3
|
+
from confgate._core import Decision
|
|
4
|
+
from confgate._exceptions import GateError, InvalidDecisionError
|
|
5
|
+
from confgate._gate import gate
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__all__ = ["Decision", "gate", "GateError", "InvalidDecisionError"]
|
confgate/_core.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Decision dataclass — the core data structure for confgate."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
_VALID_SEVERITIES = {"low", "medium", "high", "critical"}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Decision:
|
|
10
|
+
"""A structured finding produced by an LLM agent.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
category: Type of finding, e.g. 'security' or 'style'.
|
|
14
|
+
confidence: Agent's self-reported confidence, 0.0–1.0.
|
|
15
|
+
reasoning: One-sentence explanation shown to end users.
|
|
16
|
+
severity: Impact level — 'low', 'medium', 'high', or 'critical'.
|
|
17
|
+
line_ref: Optional code location, e.g. 'src/auth.py:42'.
|
|
18
|
+
abstained: Set True by @gate when confidence < threshold.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
category: str
|
|
22
|
+
confidence: float
|
|
23
|
+
reasoning: str
|
|
24
|
+
severity: str = "medium"
|
|
25
|
+
line_ref: str | None = None
|
|
26
|
+
abstained: bool = False
|
|
27
|
+
|
|
28
|
+
def __post_init__(self) -> None:
|
|
29
|
+
if not (0.0 <= self.confidence <= 1.0):
|
|
30
|
+
raise ValueError(
|
|
31
|
+
f"confidence must be between 0.0 and 1.0, got {self.confidence}"
|
|
32
|
+
)
|
|
33
|
+
if self.severity not in _VALID_SEVERITIES:
|
|
34
|
+
raise ValueError(
|
|
35
|
+
f"severity must be one of {sorted(_VALID_SEVERITIES)}, got {self.severity!r}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def to_dict(self) -> dict:
|
|
39
|
+
"""Return a plain dict suitable for JSON serialisation."""
|
|
40
|
+
return {
|
|
41
|
+
"category": self.category,
|
|
42
|
+
"confidence": self.confidence,
|
|
43
|
+
"reasoning": self.reasoning,
|
|
44
|
+
"severity": self.severity,
|
|
45
|
+
"line_ref": self.line_ref,
|
|
46
|
+
"abstained": self.abstained,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
abstained_tag = " [ABSTAINED]" if self.abstained else ""
|
|
51
|
+
loc = f" @ {self.line_ref}" if self.line_ref else ""
|
|
52
|
+
return (
|
|
53
|
+
f"[{self.severity.upper()}]{abstained_tag} {self.category}{loc}"
|
|
54
|
+
f" (confidence={self.confidence:.2f}): {self.reasoning}"
|
|
55
|
+
)
|
confgate/_exceptions.py
ADDED
confgate/_gate.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""@gate decorator — confidence-gates a function that returns a Decision."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from functools import wraps
|
|
5
|
+
from typing import TypeVar
|
|
6
|
+
|
|
7
|
+
from confgate._core import Decision
|
|
8
|
+
from confgate._exceptions import InvalidDecisionError
|
|
9
|
+
|
|
10
|
+
F = TypeVar("F", bound=Callable[..., Decision])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def gate(threshold: float = 0.8) -> Callable[[F], F]:
|
|
14
|
+
"""Decorator factory that abstains low-confidence decisions.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
threshold: Minimum confidence required to pass. Decisions with
|
|
18
|
+
confidence strictly below this value have abstained=True.
|
|
19
|
+
Must be between 0.0 and 1.0 inclusive.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
ValueError: At decoration time if threshold is outside [0.0, 1.0].
|
|
23
|
+
InvalidDecisionError: At call time if the wrapped function does not
|
|
24
|
+
return a Decision instance.
|
|
25
|
+
"""
|
|
26
|
+
if not (0.0 <= threshold <= 1.0):
|
|
27
|
+
raise ValueError(
|
|
28
|
+
f"gate threshold must be between 0.0 and 1.0, got {threshold}"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def decorator(fn: F) -> F:
|
|
32
|
+
@wraps(fn)
|
|
33
|
+
def wrapper(*args, **kwargs):
|
|
34
|
+
result = fn(*args, **kwargs)
|
|
35
|
+
if not isinstance(result, Decision):
|
|
36
|
+
raise InvalidDecisionError(
|
|
37
|
+
f"{fn.__name__} must return a Decision instance, "
|
|
38
|
+
f"got {type(result).__name__}"
|
|
39
|
+
)
|
|
40
|
+
if result.confidence < threshold:
|
|
41
|
+
result.abstained = True
|
|
42
|
+
return result
|
|
43
|
+
|
|
44
|
+
return wrapper # type: ignore[return-value]
|
|
45
|
+
|
|
46
|
+
return decorator
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: confgate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Confidence-gated decisions for LLM agent outputs
|
|
5
|
+
Author: Sri Harsha
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: agents,llm,confidence,ai,agentic
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# confgate
|
|
20
|
+
|
|
21
|
+
Confidence-gated decisions for LLM agent outputs.
|
|
22
|
+
|
|
23
|
+
> Prevent false-positive fatigue by abstaining from low-confidence findings.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install confgate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from confgate import Decision, gate
|
|
35
|
+
|
|
36
|
+
@gate(threshold=0.75)
|
|
37
|
+
def security_agent(diff: str) -> Decision:
|
|
38
|
+
# your LLM call here
|
|
39
|
+
return Decision(
|
|
40
|
+
category="security",
|
|
41
|
+
confidence=0.9,
|
|
42
|
+
reasoning="Potential SQL injection in query builder.",
|
|
43
|
+
severity="high",
|
|
44
|
+
line_ref="src/db.py:42",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
result = security_agent(diff)
|
|
48
|
+
if not result.abstained:
|
|
49
|
+
print(result)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
confgate/__init__.py,sha256=kXiJVx_TQz26BsZg7ITBYiCI4hQs18-nKF4cWRBuN2w,294
|
|
2
|
+
confgate/_core.py,sha256=AOyCQE1s0p2WOgIb8hd89lQGgA9U5CReIx4XDly86wY,1929
|
|
3
|
+
confgate/_exceptions.py,sha256=Cs723XMHa5Q2I0zG604PRZlfyZRbnTYAiYooIAQksas,237
|
|
4
|
+
confgate/_gate.py,sha256=NNiD0flQ345jjVWMbIk35RPvm-h0YUPnPmANxTabFWs,1580
|
|
5
|
+
confgate-0.1.0.dist-info/licenses/LICENSE,sha256=iDLjLh3XbHcjbWPHeOPPmaLOoR9cYTKzAvba2mMm3xg,1068
|
|
6
|
+
confgate-0.1.0.dist-info/METADATA,sha256=hREsMW2_PLzxSmWE4e3aD5IkW25qSutrIEqytZdv-7M,1244
|
|
7
|
+
confgate-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
confgate-0.1.0.dist-info/top_level.txt,sha256=NAVONwK2CvnM_UmVPKQlT3BPuKBBhzy11vNMtoiVpRM,9
|
|
9
|
+
confgate-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sri Harsha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
confgate
|