refactor: CapiscioGuard as typed passthrough (Other TypeVar)#5
Merged
Conversation
…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
c30bce6 to
2455cc4
Compare
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors
CapiscioGuardto 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'sRunnablePassthrough. Pure passthrough — always returns input unchanged. Verification metadata stored inCapiscioRequestContextcontext var, not dict enrichment._context.py: ExtendedCapiscioRequestContextwithverified: boolandwarnings: list[str] | Nonefields.guard.py (ainvoke): Fixed context propagation across thread boundaries using closure capture.test_string_passthrough_with_badge_in_configtest 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 showsCapiscioGuard() | ChatOpenAI()— this implementation makes that truthful.Tests
All 39 tests pass.