Skip to content

[python] PoC: AI Guard test under INTEGRATION_FRAMEWORKS#7257

Open
avara1986 wants to merge 8 commits into
mainfrom
avara/appsec-68977-integration-frameworks-ai-guard-poc
Open

[python] PoC: AI Guard test under INTEGRATION_FRAMEWORKS#7257
avara1986 wants to merge 8 commits into
mainfrom
avara/appsec-68977-integration-frameworks-ai-guard-poc

Conversation

@avara1986

Copy link
Copy Markdown
Member

What

Proof-of-concept exploring whether AI Guard coverage can be consolidated under the INTEGRATION_FRAMEWORKS scenario instead of the dedicated AI_GUARD scenario.

Adds tests/integration_frameworks/llm/openai/test_openai_ai_guard.py, which drives AI Guard evaluation through the OpenAI framework weblog using the test_client/test_agent fixtures, and asserts on the ai_guard span (meta.ai_guard.*, meta_struct.ai_guard) — reusing the payloads and span shape from tests/ai_guard/test_ai_guard_sdk.py.

Status: DRAFT / investigation

This is a scaffold for the investigation tracked in APPSEC-68977. It is not runnable yet — it depends on prerequisites still to be validated:

  • an /ai_guard/evaluate endpoint in utils/build/docker/python/openai_app/openai.py that calls the tracer's AI Guard client;
  • the test-agent VCR proxy serving an /vcr/aiguard upstream (or reusing the standalone VCRCassettesContainer);
  • DD_AI_GUARD_ENABLED / DD_AI_GUARD_ENDPOINT wired into IntegrationFrameworksScenario.

Jira

Investigation task: https://datadoghq.atlassian.net/browse/APPSEC-68977 (under epic APPSEC-68823)

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

CODEOWNERS have been resolved as:

tests/integration_frameworks/llm/openai/test_openai_ai_guard.py         @DataDog/ml-observability
tests/integration_frameworks/utils/vcr-cassettes/aiguard/test_after_model_validation_stream_True_aiguard_evaluate_post_5dec5d6a.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/aiguard/test_before_model_validation_aiguard_evaluate_post_ca44130a.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/aiguard/test_before_model_validation_aiguard_evaluate_post_d13cc790.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/aiguard/test_tool_call_validation_aiguard_evaluate_post_9e556a11.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/aiguard/test_tool_call_validation_aiguard_evaluate_post_a304603c.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/openai/test_after_model_validation_stream_True_openai_chat_completions_post_5c14b241.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/openai/test_before_model_validation_openai_chat_completions_post_eb8df755.json  @DataDog/system-tests-core
tests/integration_frameworks/utils/vcr-cassettes/openai/test_tool_call_validation_openai_chat_completions_post_f2dffea2.json  @DataDog/system-tests-core
manifests/java.yml                                                      @DataDog/asm-java @DataDog/apm-java
manifests/nodejs.yml                                                    @DataDog/dd-trace-js
manifests/python.yml                                                    @DataDog/apm-python @DataDog/asm-python
utils/docker_fixtures/_test_agent.py                                    @DataDog/system-tests-core
utils/docker_fixtures/_test_clients/_test_client_framework_integrations.py  @DataDog/system-tests-core

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 3, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: d95adff | Docs | Datadog PR Page | Give us feedback!

@avara1986 avara1986 force-pushed the avara/appsec-68977-integration-frameworks-ai-guard-poc branch from 78379f1 to ca1a97f Compare July 3, 2026 13:02
@avara1986 avara1986 changed the title PoC: AI Guard test under INTEGRATION_FRAMEWORKS (APPSEC-68977) [python] PoC: AI Guard test under INTEGRATION_FRAMEWORKS Jul 3, 2026
…APPSEC-68977)

Exercise the auto-instrumented AI Guard/OpenAI integration (ai_guard_listen)
the way the LLM Obs suite does: call the OpenAI SDK directly through the
existing /chat/completions weblog endpoint with DD_AI_GUARD_ENABLED=true, and
assert an ai_guard span is emitted for before-model, after-model (streamed)
and tool-call evaluation. The evaluation outcome (ALLOW/DENY/ABORT) stays
covered by the dedicated AI_GUARD scenario and is not re-asserted here.

The AI Guard endpoint is not yet wired into the INTEGRATION_FRAMEWORKS
scenario (no DD_AI_GUARD_ENDPOINT / no aiguard VCR cassettes), so the
integration path 500s for every language. Marked missing_feature for
python, nodejs and java until the scenario wiring + cassettes land.

Investigation task: APPSEC-68977

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@avara1986 avara1986 force-pushed the avara/appsec-68977-integration-frameworks-ai-guard-poc branch from ca1a97f to 4de1a84 Compare July 3, 2026 13:15
avara1986 and others added 3 commits July 3, 2026 16:00
library_env now injects real DD_API_KEY/DD_APP_KEY in --generate-cassettes
mode (the AI Guard client calls the real API to record the aiguard cassette)
and keeps mock keys on replay, where the VCR proxy matches on the request
rather than auth.

Investigation task: APPSEC-68977

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread tests/integration_frameworks/llm/openai/test_openai_ai_guard.py Outdated
@avara1986 avara1986 marked this pull request as ready for review July 15, 2026 14:42
@avara1986 avara1986 requested review from a team as code owners July 15, 2026 14:42
@avara1986 avara1986 requested review from brettlangdon, claponcet, manuel-alvarez-alvarez and wconti27 and removed request for a team July 15, 2026 14:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d95adff1f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/integration_frameworks/llm/openai/test_openai_ai_guard.py
Comment thread tests/integration_frameworks/llm/openai/test_openai_ai_guard.py
Comment thread tests/integration_frameworks/llm/openai/test_openai_ai_guard.py
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