Skip to content

Commit f80b47d

Browse files
avara1986claude
andauthored
[python] migrate python weblog to ddtrace.aiguard imports (#7334)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b1ab71f commit f80b47d

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • utils/build/docker/python/flask

utils/build/docker/python/flask/app.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,13 +2231,22 @@ def external_request_redirect():
22312231
@app.route("/ai_guard/evaluate", methods=["POST"])
22322232
def ai_guard_evaluate():
22332233
"""AI Guard evaluation endpoint."""
2234-
from ddtrace.internal.settings.asm import ai_guard_config
2234+
# AI Guard was moved from `ddtrace.appsec.ai_guard` to the top-level `ddtrace.aiguard`
2235+
# package (dd-trace-py#18754, #19110). Import the new location first and fall back to
2236+
# the old one to stay compatible with every tracer version under test.
2237+
try:
2238+
from ddtrace.internal.settings.aiguard import aiguard_config
2239+
except ImportError:
2240+
from ddtrace.internal.settings.asm import ai_guard_config as aiguard_config
22352241

2236-
if not ai_guard_config._ai_guard_enabled:
2242+
if not aiguard_config._ai_guard_enabled:
22372243
return jsonify({"action": "ALLOW", "reason": "AI Guard not enabled"}), 200
22382244

22392245
try:
2240-
from ddtrace.appsec.ai_guard import new_ai_guard_client, Options, AIGuardAbortError
2246+
try:
2247+
from ddtrace.aiguard import new_ai_guard_client, Options, AIGuardAbortError
2248+
except ImportError:
2249+
from ddtrace.appsec.ai_guard import new_ai_guard_client, Options, AIGuardAbortError
22412250
from ddtrace.appsec.track_user_sdk import track_user_id
22422251

22432252
should_block = flask_request.headers.get("X-AI-Guard-Block", "false").lower() == "true"

0 commit comments

Comments
 (0)