Skip to content
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e5aa7a4
test(errors): prove rejected-value confidentiality RED
seonghobae Aug 15, 2026
8fff42d
fix(errors): redact rejected values by default
seonghobae Aug 15, 2026
e1d6b84
test(errors): cover explicit bounded diagnostic evidence
seonghobae Aug 15, 2026
23a15c9
test(api): require endpoint validation redaction
seonghobae Aug 15, 2026
abfa4c0
test(orchestrator): redact unknown batch selectors
seonghobae Aug 15, 2026
ae0713e
test(orchestrator): classify safe token-limit diagnostics
seonghobae Aug 15, 2026
2a4c5bd
fix(orchestrator): expose only bounded numeric limit evidence
seonghobae Aug 15, 2026
6596a79
test(lifecycle): expect redacted callable evidence
seonghobae Aug 15, 2026
e2f4abc
test(tenant): redact rejected tenant identities
seonghobae Aug 15, 2026
04063bb
test(tokens): redact oversized record diagnostics
seonghobae Aug 15, 2026
731c5f9
fix(errors): preserve bounded lifecycle sentinel evidence
seonghobae Aug 15, 2026
afe5cc8
test(errors): prove bounded numeric evidence policy
seonghobae Aug 15, 2026
c9dd77c
fix(errors): bound token-limit diagnostic rendering
seonghobae Aug 15, 2026
7aad177
test(errors): cover integer rendering fallback
seonghobae Aug 15, 2026
71540e1
test(errors): reject hostile safe-value subclasses
seonghobae Aug 17, 2026
cb4689f
fix(errors): require exact safe-value strings
seonghobae Aug 17, 2026
3ec0140
fix(privacy): isolate validation error confidentiality on current root
seonghobae Sep 13, 2026
43f381a
fix(privacy): serialize validation confidentiality after driver migra…
seonghobae Sep 13, 2026
5a9685f
test(privacy): assert redacted batch lookup diagnostics
seonghobae Sep 13, 2026
96a1bfc
test(privacy): redact oversized record diagnostics
seonghobae Sep 13, 2026
b67ff2d
test(privacy): align rejected-value evidence with fail-closed redaction
seonghobae Sep 13, 2026
b8fd11a
test(privacy): redact tenant recorder seam evidence
seonghobae Sep 13, 2026
53b7549
chore(pr202): reconcile privacy child with current postgres parent
seonghobae Sep 15, 2026
a5764e9
chore(pr202): reconcile privacy child with current postgres parent
seonghobae Sep 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pg_llm_batch/durable_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def __init__(
field="lifecycle_recorder",
value="<provided>",
reason="tenant clients require tenant_lifecycle_recorder",
safe_value="<provided>",
)
_validate_callable_seam(
"tenant_lifecycle_recorder",
Expand Down
40 changes: 37 additions & 3 deletions pg_llm_batch/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from typing import Any, Dict, Optional


_VALIDATION_REDACTED_VALUE = "<redacted>"
_MAX_SAFE_VALIDATION_VALUE_CHARS = 128


class PgLlmBatchError(Exception):
"""Base error for all pg_llm_batch failures."""

Expand Down Expand Up @@ -66,13 +70,43 @@ def __init__(
value: Any = None,
reason: str = "",
message: Optional[str] = None,
*,
safe_value: Optional[str] = None,
) -> None:
"""Describe an invalid field value and its reason."""
rendered = message or f"Invalid value for '{field}': {value!r} ({reason})"
"""Describe invalid input without exporting rejected content by default.

``value`` is retained only for call compatibility and is deliberately never
rendered, copied into details, or otherwise inspected. A caller may instead
provide ``safe_value`` after explicitly determining that the diagnostic is
non-sensitive. That evidence must be a bounded printable ASCII string so an
exception cannot become an unbounded or control-character-bearing log sink.
"""
if safe_value is not None:
if not isinstance(safe_value, str):
raise TypeError("safe_value must be a string or None")
if (
not safe_value
or len(safe_value) > _MAX_SAFE_VALIDATION_VALUE_CHARS
or any(ord(character) < 32 or ord(character) > 126 for character in safe_value)
):
raise ValueError(
"safe_value must contain 1-128 printable ASCII characters"
)
evidence_value = safe_value
else:
evidence_value = _VALIDATION_REDACTED_VALUE

if message is not None:
rendered = message
elif safe_value is not None:
rendered = f"Invalid value for '{field}': {safe_value} ({reason})"
else:
rendered = f"Invalid value for '{field}' ({reason})"

super().__init__(
message=rendered,
error_code="VALIDATION_ERROR",
details={"field": field, "value": value, "reason": reason},
details={"field": field, "value": evidence_value, "reason": reason},
)


Expand Down
2 changes: 2 additions & 0 deletions pg_llm_batch/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ def _validate_effective_token_limit(value: Optional[int]) -> Optional[int]:
if value is None:
return None
if isinstance(value, bool) or not isinstance(value, int) or value <= 0:
safe_value = str(value) if isinstance(value, (bool, int, float)) else None
raise ValidationError(
field="effective_token_limit",
value=value,
reason="must be a positive integer when provided",
safe_value=safe_value,
Comment thread
seonghobae marked this conversation as resolved.
Resolved
)
return value

Expand Down
4 changes: 3 additions & 1 deletion tests/test_batch_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def test_prepare_batches_rejects_unknown_lookup_key(monkeypatch, fake_pg):
orch.prepare_batches(batch_uuid="missing-input.jsonl")

assert exc_info.value.details["field"] == "batch_uuid"
assert exc_info.value.details["value"] == "missing-input.jsonl"
assert exc_info.value.details["value"] == "<redacted>"
assert "missing-input.jsonl" not in str(exc_info.value)
assert "missing-input.jsonl" not in repr(exc_info.value.details)
assert connect_calls == []


Expand Down
5 changes: 4 additions & 1 deletion tests/test_batch_endpoint_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def test_invalid_batch_endpoints_raise_structured_validation_errors(endpoint):
_validate_batch_endpoint(endpoint)

assert exc_info.value.details["field"] == "endpoint"
assert exc_info.value.details["value"] == endpoint
assert exc_info.value.details["value"] == "<redacted>"
assert "queries" in exc_info.value.details["reason"]
if isinstance(endpoint, str) and endpoint:
assert endpoint not in str(exc_info.value)
assert endpoint not in repr(exc_info.value.details)


class Credentials:
Expand Down
21 changes: 17 additions & 4 deletions tests/test_effective_token_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,28 @@ def test_missing_token_limit_preserves_configured_default():
assert _validate_effective_token_limit(None) is None


@pytest.mark.parametrize("value", [0, -1, True, False, 1.5, "100", object()])
def test_invalid_token_limits_raise_structured_validation_errors(value):
"""Coercive, disabled, fractional, and non-positive values fail closed."""
@pytest.mark.parametrize(
("value", "expected_evidence"),
[
(0, "0"),
(-1, "-1"),
(True, "True"),
(False, "False"),
(1.5, "1.5"),
("100", "<redacted>"),
(object(), "<redacted>"),
],
)
def test_invalid_token_limits_raise_structured_validation_errors(
value, expected_evidence
):
"""Only bounded numeric configuration evidence is explicitly disclosed."""
with pytest.raises(ValidationError, match="effective_token_limit") as exc_info:
_validate_effective_token_limit(value)

assert exc_info.value.details == {
"field": "effective_token_limit",
"value": value,
"value": expected_evidence,
"reason": "must be a positive integer when provided",
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_lifecycle_seam_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_standalone_client_rejects_non_callable_lifecycle_seams(

assert exc_info.value.details == {
"field": option_name,
"value": None,
"value": "<redacted>",
"reason": expected_reason,
}

Expand All @@ -60,6 +60,6 @@ def test_tenant_client_rejects_a_non_callable_tenant_recorder() -> None:

assert exc_info.value.details == {
"field": "tenant_lifecycle_recorder",
"value": None,
"value": "<redacted>",
"reason": "must be callable",
}
7 changes: 5 additions & 2 deletions tests/test_tenant_scope_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ def test_default_tenant_scope_is_explicit_standalone_identity() -> None:
def test_validate_tenant_scope_rejects_ambiguous_or_unsafe_values(
tenant_scope: Any,
) -> None:
"""Unsupported scope values fail with bounded structured diagnostics."""
"""Unsupported tenant identities fail without exporting rejected content."""
with pytest.raises(ValidationError) as exc_info:
validate_tenant_scope(tenant_scope)

assert exc_info.value.details == {
"field": "tenant_scope",
"value": tenant_scope,
"value": "<redacted>",
"reason": (
"must be 1-128 ASCII characters beginning with an alphanumeric "
"character and containing only letters, digits, dot, underscore, "
"colon, or hyphen"
),
}
if isinstance(tenant_scope, str) and tenant_scope:
assert tenant_scope not in str(exc_info.value)
assert tenant_scope not in repr(exc_info.value.details)
2 changes: 1 addition & 1 deletion tests/test_token_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_batch_accumulator_rejects_oversized_first_record(fake_pg):
acc.add_entry("request-bytes", "{}", tokens=1, byte_size=11)
assert byte_error.value.details == {
"field": "byte_size",
"value": 11,
"value": "<redacted>",
"reason": "single JSONL record exceeds max_bytes=10",
}
assert acc.entries == []
Expand Down
89 changes: 89 additions & 0 deletions tests/test_validation_error_confidentiality_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# SPDX-License-Identifier: Apache-2.0
"""Confidentiality regressions for rejected-value validation evidence."""

from __future__ import annotations

import pytest

from pg_llm_batch.exceptions import ValidationError


def test_default_validation_error_does_not_retain_or_render_rejected_content() -> None:
"""Arbitrary rejected content must stay outside package-owned error evidence."""
secret = "credential-shaped-sentinel-7f4a6b89"

error = ValidationError(
field="api_key",
value=secret,
reason="must satisfy the configured policy",
)

assert secret not in str(error)
assert secret not in repr(error)
assert secret not in repr(error.args)
assert secret not in repr(error.details)
assert error.details == {
"field": "api_key",
"value": "<redacted>",
"reason": "must satisfy the configured policy",
}


def test_default_validation_error_never_calls_rejected_value_repr() -> None:
"""Safe-default construction must not execute caller-controlled rendering."""

class HostileRejectedValue:
def __repr__(self) -> str:
raise AssertionError("rejected value repr must not run")

error = ValidationError(
field="payload",
value=HostileRejectedValue(),
reason="must be a supported value",
)

assert str(error) == (
"[VALIDATION_ERROR] Invalid value for 'payload' (must be a supported value)"
)
assert error.details["value"] == "<redacted>"


def test_reviewed_safe_value_is_bounded_explicit_evidence() -> None:
"""Callers may expose only a separately supplied reviewed diagnostic string."""
secret = "actual-rejected-secret"

error = ValidationError(
field="mode",
value=secret,
reason="must name a supported mode",
safe_value="unsupported-mode",
)

assert secret not in str(error)
assert secret not in repr(error.details)
assert error.details["value"] == "unsupported-mode"
assert str(error) == (
"[VALIDATION_ERROR] Invalid value for 'mode': unsupported-mode "
"(must name a supported mode)"
)


def test_safe_value_rejects_non_string_evidence() -> None:
"""Explicit evidence authority must not reintroduce arbitrary object rendering."""
with pytest.raises(TypeError, match="safe_value must be a string or None"):
ValidationError(field="mode", value="secret", safe_value=1) # type: ignore[arg-type]


@pytest.mark.parametrize(
"safe_value",
["", "x" * 129, "line\nbreak", "non-ascii-é"],
)
def test_safe_value_rejects_unbounded_or_non_printable_evidence(
safe_value: str,
) -> None:
"""Explicit evidence remains finite, printable ASCII suitable for logs."""
with pytest.raises(
ValueError,
match="safe_value must contain 1-128 printable ASCII characters",
):
ValidationError(field="mode", value="secret", safe_value=safe_value)
Loading