You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(aiguard): move AI Guard to top-level ddtrace.aiguard package (#18754)
## Description
Moves the AI Guard SDK out of the AppSec tree (`ddtrace/appsec/ai_guard` + `ddtrace/appsec/_ai_guard`) into a new top-level **`ddtrace/aiguard`** package, so the Python import path matches the other tracers — Node (`dd-trace/aiguard`) and Java (`datadog.trace.api.aiguard`) — and is no longer conflated with AAP/AppSec.
- New package `ddtrace/aiguard/`: cross-provider core (`_listener`, `_context`, `_common`, `_streaming`, `messages`, `_api_client`, `_initialization`) at top level; provider listeners/plugins under `ddtrace/aiguard/integrations/`.
- `init_ai_guard` is now `load_ai_guard` in `ddtrace/aiguard/_initialization.py`; the AppSec product loader imports it from there.
- **Backwards compatibility:** `ddtrace.appsec.ai_guard` remains as a lazy re-export shim that emits `ddtrace.DDTraceDeprecationWarning` on access and forwards to `ddtrace.aiguard`. Scheduled for removal in **5.0.0**.
- Tests moved to `tests/aiguard/` with their own `tests/aiguard/suitespec.yml` (split out of `tests/appsec/suitespec.yml`); `riotfile.py` test paths updated.
JIRA: [APPSEC-67628](https://datadoghq.atlassian.net/browse/APPSEC-67628)
## Testing
- New `tests/aiguard/api/test_compat_imports.py` asserts every public symbol is importable from the old `ddtrace.appsec.ai_guard` path, resolves to the same object as `ddtrace.aiguard`, and emits `DDTraceDeprecationWarning`.
- Ran `ai_guard_api` (88 passed) and `ai_guard_strands` (130 passed) locally — the latter includes the `TestLazyImport` Strands regression test, confirming the lazy-load contract survives the move. Other suites (openai/anthropic/langchain/litellm) are unchanged mechanically; their optional SDKs aren't installed in the local base env.
- `scripts/lint` `fmt` / `suitespec-check` / `error-log-check` / `riot` all pass.
## Risks
- Low. Pure relocation + import rewrites behind a backwards-compatible shim; no public API contract changes. The deprecated path keeps working until 5.0.0.
- Provider abort-error `__module__` identities now point to `ddtrace.aiguard.integrations.{openai,anthropic}` (used for span `error.type`).
## Additional Notes
- Release note added under `deprecations`.
- `docs/upgrading.rst` gains an "Upgrade to 5.0" entry; `.cursor/rules/ai-guard.mdc`, `AGENTS.md`, and the `.sg` rule updated to the new layout.
[APPSEC-67628]: https://datadoghq.atlassian.net/browse/APPSEC-67628?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: alberto.vara <alberto.vara@datadoghq.com>
0 commit comments