Skip to content

Fix safety event emission + add cassette tests for LangChain, LlamaIndex, LiteLLM - #16

Merged
manas-fortifyroot merged 1 commit into
fr-v0.52.6.xfrom
fix/safety-event-emission-langchain-llamaindex
Apr 2, 2026
Merged

Fix safety event emission + add cassette tests for LangChain, LlamaIndex, LiteLLM#16
manas-fortifyroot merged 1 commit into
fr-v0.52.6.xfrom
fix/safety-event-emission-langchain-llamaindex

Conversation

@manas-fortifyroot

Copy link
Copy Markdown

Summary

  • Bug fix: Safety span events were silently dropped for LangChain and
    LlamaIndex because the safety handler ran before the OTel span existed.
    Events are now buffered and emitted once the span is available.
  • LlamaIndex dispatcher: Always creates a span for all LLM classes
    (previously skipped for OpenAI). Provider instrumentor still creates its
    child span via SUPPRESS=False. No telemetry duplication.
  • New tests: 37 VCR cassette tests across LangChain (10), LlamaIndex (9),
    and LiteLLM (18) covering safety masking, span events, telemetry attributes,
    dual-span hierarchy, and streaming.
  • LiteLLM VCR infra: Added pytest-recording + vcrpy deps, enhanced conftest
    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
  • Cassette replay verified with --record-mode=none for all 37 tests

…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
manas-fortifyroot merged commit f0f0d8b into fr-v0.52.6.x Apr 2, 2026
9 checks passed
@manas-fortifyroot
manas-fortifyroot deleted the fix/safety-event-emission-langchain-llamaindex branch April 2, 2026 11:01
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