Fix safety event emission + add cassette tests for LangChain, LlamaIndex, LiteLLM - #16
Merged
manas-fortifyroot merged 1 commit intoApr 2, 2026
Conversation
…tation Safety findings were silently dropped when the safety handler ran before the OTel span was created. Findings are now buffered in a thread-local queue and emitted once the real span is available. Also adds VCR cassette tests for LangChain, LlamaIndex, and LiteLLM covering prompt masking, completion capture, and safety event verification across all three rule types (regex, list, UDF) and both MASK/ALLOW actions. Changes: - fortifyroot: deferred finding buffer (discard/emit/drain/inject API) - langchain: flush deferred findings in callback handler after span creation - llamaindex: always create span in dispatcher (removes early-return for OpenLLMetry classes); flush deferred findings in new_span() - litellm: add VCR test infrastructure (conftest, pyproject deps) - all three: new test_safety_cassettes.py + test_telemetry_cassettes.py with recorded cassettes (37 tests, 37 YAML cassettes)
manas-fortifyroot
deleted the
fix/safety-event-emission-langchain-llamaindex
branch
April 2, 2026 11:01
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
LlamaIndex because the safety handler ran before the OTel span existed.
Events are now buffered and emitted once the span is available.
(previously skipped for OpenAI). Provider instrumentor still creates its
child span via SUPPRESS=False. No telemetry duplication.
and LiteLLM (18) covering safety masking, span events, telemetry attributes,
dual-span hierarchy, and streaming.
with OTel exporters and VCR config.
Test plan
./scripts/run-tests.sh --all— 1278 passed, 0 failed (all 35 packages)./scripts/run-tests.sh --all --package '*langchain*'— 123 passed./scripts/run-tests.sh --all --package '*llamaindex*'— 65 passed./scripts/run-tests.sh --all --package '*litellm*'— 57 passed./scripts/run-tests.sh --all --package '*fortifyroot*'— 19 passed--record-mode=nonefor all 37 tests