Skip to content

refactor: CapiscioGuard as typed passthrough (Other TypeVar)#5

Merged
beonde merged 4 commits into
mainfrom
feat/zero-config-guard
Mar 16, 2026
Merged

refactor: CapiscioGuard as typed passthrough (Other TypeVar)#5
beonde merged 4 commits into
mainfrom
feat/zero-config-guard

Conversation

@beonde

@beonde beonde commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Refactors CapiscioGuard to use the correct LangChain typing pattern: RunnableSerializable[Other, Other] — a typed identity passthrough that works transparently in any LCEL chain.

Changes

  • guard.py: Other = TypeVar('Other') pattern matching LangChain's RunnablePassthrough. Pure passthrough — always returns input unchanged. Verification metadata stored in CapiscioRequestContext context var, not dict enrichment.
  • _context.py: Extended CapiscioRequestContext with verified: bool and warnings: list[str] | None fields.
  • guard.py (ainvoke): Fixed context propagation across thread boundaries using closure capture.
  • Tests: All assertions updated from dict enrichment checks to context var checks. New test_string_passthrough_with_badge_in_config test verifies LCEL pipe compatibility with string inputs.

Why

The previous RunnableSerializable[dict, dict] typing meant CapiscioGuard could not participate in standard LCEL pipes (string input → ChatOpenAI). The marketing site shows CapiscioGuard() | ChatOpenAI() — this implementation makes that truthful.

Tests

All 39 tests pass.

…her, Other])

- Use Other = TypeVar('Other') pattern matching LangChain's RunnablePassthrough
- Pure identity passthrough: invoke always returns input unchanged
- Verification metadata stored in CapiscioRequestContext (not dict enrichment)
- Extended CapiscioRequestContext with verified and warnings fields
- Fixed ainvoke context propagation across thread boundaries
- Updated all test assertions to check context vars instead of dict output
- Added string passthrough test to verify LCEL pipe compatibility
beonde added 3 commits March 13, 2026 17:06
- pyproject.toml: Repository + Issues URLs
- README.md: git clone URL + cd command
- publish.yml: changelog compare URL
Ruff F401/F821: TypeVar was imported but never used to define Other,
causing 'undefined name' errors on all method signatures.
@beonde beonde merged commit b35ff85 into main Mar 16, 2026
5 checks passed
@beonde beonde deleted the feat/zero-config-guard branch March 16, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant