contractgate 0.3.1__tar.gz → 0.3.2__tar.gz
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.
- {contractgate-0.3.1 → contractgate-0.3.2}/CHANGELOG.md +6 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/PKG-INFO +1 -1
- {contractgate-0.3.1 → contractgate-0.3.2}/pyproject.toml +1 -1
- contractgate-0.3.2/src/contractgate/_version.py +1 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/llm.py +16 -12
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/test_llm_gate.py +17 -6
- contractgate-0.3.1/src/contractgate/_version.py +0 -1
- {contractgate-0.3.1 → contractgate-0.3.2}/.gitignore +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/LICENSE +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/README.md +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/__init__.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/_transport.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/async_client.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/client.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/contract.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/exceptions.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/models.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/src/contractgate/validator.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/__init__.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/conftest.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/fixtures/contracts/compliance_mode.yaml +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/fixtures/contracts/user_events.yaml +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/fixtures/contracts/with_transform.yaml +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/test_client_async.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/test_client_sync.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/test_contract_parse.py +0 -0
- {contractgate-0.3.1 → contractgate-0.3.2}/tests/test_validator.py +0 -0
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the `contractgate` Python SDK.
|
|
4
4
|
|
|
5
|
+
## 0.3.2 — 2026-10-13
|
|
6
|
+
|
|
7
|
+
- `LLMGate` / `AsyncLLMGate`: `llm` is now optional. `validate_only()` never
|
|
8
|
+
calls a provider, so it no longer needs a dummy client; `completion()` and
|
|
9
|
+
`message()` raise `ValueError` when no `llm` is bound.
|
|
10
|
+
|
|
5
11
|
## 0.3.1 — 2026-10-13
|
|
6
12
|
|
|
7
13
|
Fixes from end-to-end testing against production. No API changes.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: contractgate
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Python SDK for DataContractGate — high-performance semantic contract enforcement gateway.
|
|
5
5
|
Project-URL: Homepage, https://datacontractgate.com
|
|
6
6
|
Project-URL: Source, https://github.com/nightmoose/contractgate
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "contractgate"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.2"
|
|
8
8
|
description = "Python SDK for DataContractGate — high-performance semantic contract enforcement gateway."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.2"
|
|
@@ -306,6 +306,16 @@ def _egress_from_rejection(err: ValidationFailedError) -> EgressResponse:
|
|
|
306
306
|
raise err
|
|
307
307
|
|
|
308
308
|
|
|
309
|
+
def _require_llm(llm: Any) -> None:
|
|
310
|
+
"""``llm`` is only needed to call a provider; ``validate_only`` works without it."""
|
|
311
|
+
if llm is None:
|
|
312
|
+
raise ValueError(
|
|
313
|
+
"completion() and message() need an `llm` client (OpenAI / Anthropic / "
|
|
314
|
+
"Ollama / vLLM). Example: LLMGate(..., llm=OpenAI()). "
|
|
315
|
+
"validate_only() works without one."
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
|
|
309
319
|
def _append_user_message(messages: List[Dict[str, Any]], hint: str) -> List[Dict[str, Any]]:
|
|
310
320
|
return list(messages) + [{"role": "user", "content": hint}]
|
|
311
321
|
|
|
@@ -329,7 +339,7 @@ class LLMGate:
|
|
|
329
339
|
*,
|
|
330
340
|
api_key: str,
|
|
331
341
|
contract_id: str,
|
|
332
|
-
llm: Any,
|
|
342
|
+
llm: Any = None,
|
|
333
343
|
base_url: str = "https://api.datacontractgate.com",
|
|
334
344
|
version: Optional[str] = None,
|
|
335
345
|
disposition: Optional[str] = None,
|
|
@@ -337,11 +347,6 @@ class LLMGate:
|
|
|
337
347
|
repair_prompt: Optional[Callable[[List[Violation]], str]] = None,
|
|
338
348
|
client: Optional[Client] = None,
|
|
339
349
|
) -> None:
|
|
340
|
-
if llm is None:
|
|
341
|
-
raise ValueError(
|
|
342
|
-
"LLMGate requires an `llm` client (OpenAI / Anthropic / "
|
|
343
|
-
"Ollama / vLLM). Example: LLMGate(..., llm=OpenAI())"
|
|
344
|
-
)
|
|
345
350
|
self._llm = llm
|
|
346
351
|
self._contract_id = contract_id
|
|
347
352
|
self._resolved: Dict[str, str] = {}
|
|
@@ -383,6 +388,7 @@ class LLMGate:
|
|
|
383
388
|
Works unchanged for vLLM and OpenAI-compatible Ollama endpoints.
|
|
384
389
|
"""
|
|
385
390
|
self._reject_stream_kwarg(provider_kwargs)
|
|
391
|
+
_require_llm(self._llm)
|
|
386
392
|
|
|
387
393
|
def call(current: List[Dict[str, Any]]) -> Any:
|
|
388
394
|
return self._llm.chat.completions.create(
|
|
@@ -402,6 +408,7 @@ class LLMGate:
|
|
|
402
408
|
) -> LLMGateResult:
|
|
403
409
|
"""Anthropic-protocol wrapper. Calls ``llm.messages.create``."""
|
|
404
410
|
self._reject_stream_kwarg(provider_kwargs)
|
|
411
|
+
_require_llm(self._llm)
|
|
405
412
|
|
|
406
413
|
def call(current: List[Dict[str, Any]]) -> Any:
|
|
407
414
|
return self._llm.messages.create(
|
|
@@ -524,7 +531,7 @@ class AsyncLLMGate:
|
|
|
524
531
|
*,
|
|
525
532
|
api_key: str,
|
|
526
533
|
contract_id: str,
|
|
527
|
-
llm: Any,
|
|
534
|
+
llm: Any = None,
|
|
528
535
|
base_url: str = "https://api.datacontractgate.com",
|
|
529
536
|
version: Optional[str] = None,
|
|
530
537
|
disposition: Optional[str] = None,
|
|
@@ -532,11 +539,6 @@ class AsyncLLMGate:
|
|
|
532
539
|
repair_prompt: Optional[Callable[[List[Violation]], str]] = None,
|
|
533
540
|
client: Optional[AsyncClient] = None,
|
|
534
541
|
) -> None:
|
|
535
|
-
if llm is None:
|
|
536
|
-
raise ValueError(
|
|
537
|
-
"AsyncLLMGate requires an `llm` client. Example: "
|
|
538
|
-
"AsyncLLMGate(..., llm=AsyncOpenAI())"
|
|
539
|
-
)
|
|
540
542
|
self._llm = llm
|
|
541
543
|
self._contract_id = contract_id
|
|
542
544
|
self._resolved: Dict[str, str] = {}
|
|
@@ -570,6 +572,7 @@ class AsyncLLMGate:
|
|
|
570
572
|
**provider_kwargs: Any,
|
|
571
573
|
) -> LLMGateResult:
|
|
572
574
|
LLMGate._reject_stream_kwarg(provider_kwargs)
|
|
575
|
+
_require_llm(self._llm)
|
|
573
576
|
|
|
574
577
|
async def call(current: List[Dict[str, Any]]) -> Any:
|
|
575
578
|
return await self._llm.chat.completions.create(
|
|
@@ -588,6 +591,7 @@ class AsyncLLMGate:
|
|
|
588
591
|
**provider_kwargs: Any,
|
|
589
592
|
) -> LLMGateResult:
|
|
590
593
|
LLMGate._reject_stream_kwarg(provider_kwargs)
|
|
594
|
+
_require_llm(self._llm)
|
|
591
595
|
|
|
592
596
|
async def call(current: List[Dict[str, Any]]) -> Any:
|
|
593
597
|
return await self._llm.messages.create(
|
|
@@ -255,9 +255,18 @@ def test_extract_json_streaming_rejected():
|
|
|
255
255
|
# ---------------------------------------------------------------------------
|
|
256
256
|
|
|
257
257
|
|
|
258
|
-
def
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
def test_llm_is_optional_for_validate_only():
|
|
259
|
+
payload = {"user_id": "alice"}
|
|
260
|
+
gate = LLMGate(
|
|
261
|
+
api_key="k",
|
|
262
|
+
contract_id="11111111-1111-4111-8111-111111111111",
|
|
263
|
+
client=_client_with_egress(_ok_egress_body(payload)),
|
|
264
|
+
)
|
|
265
|
+
assert gate.validate_only(payload).ok is True
|
|
266
|
+
with pytest.raises(ValueError, match="need an `llm` client"):
|
|
267
|
+
gate.completion(model="m", messages=[])
|
|
268
|
+
with pytest.raises(ValueError, match="need an `llm` client"):
|
|
269
|
+
gate.message(model="m", messages=[])
|
|
261
270
|
|
|
262
271
|
|
|
263
272
|
def test_llmgate_max_retries_above_cap_warns_and_clamps():
|
|
@@ -560,9 +569,11 @@ async def test_async_llmgate_validate_only_happy_path():
|
|
|
560
569
|
|
|
561
570
|
|
|
562
571
|
@pytest.mark.asyncio
|
|
563
|
-
async def
|
|
564
|
-
|
|
565
|
-
|
|
572
|
+
async def test_async_llm_is_optional_until_completion():
|
|
573
|
+
gate = AsyncLLMGate(api_key="k", contract_id="11111111-1111-4111-8111-111111111111")
|
|
574
|
+
with pytest.raises(ValueError, match="need an `llm` client"):
|
|
575
|
+
await gate.completion(model="m", messages=[])
|
|
576
|
+
await gate.aclose()
|
|
566
577
|
|
|
567
578
|
|
|
568
579
|
# ---------------------------------------------------------------------------
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|