Skip to content

Commit ae34803

Browse files
committed
fix(aicore/filtering): address PR review fixes 21-23
- Add py.typed markers to aicore/ and aicore/filtering/ packages so type checkers consuming the SDK see the inline annotations (PEP 561). - Document AICORE_FILTER_TEST_MODEL and AICORE_FILTER_TEST_SELF_HARM_PROMPT in .env_integration_tests.example alongside the existing AICORE_* entries, with a comment explaining the self-harm prompt is operator- populated and kept out of source. - Narrow extract_filter_blocked's catch-all 'except Exception' to '(ValueError, KeyError, TypeError, AttributeError)'. Documents the realistic failure modes (JSON parse, missing key, wrong shape, attr on non-object) and stops swallowing logic bugs in ContentFilteredError construction.
1 parent 286afb4 commit ae34803

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

.env_integration_tests.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ AICORE_BASE_URL=https://your-aicore-api-url-here/v2
2424
AICORE_RESOURCE_GROUP=default
2525
AICORE_MODEL=anthropic--claude-3-5-haiku
2626

27+
# AI CORE filtering integration tests (tests/aicore/integration/)
28+
# AICORE_FILTER_TEST_MODEL: sap/* model to drive the live filtering scenarios.
29+
# Use the cheapest deployment available on your tenant (e.g. sap/gpt-4o-mini).
30+
# AICORE_FILTER_TEST_SELF_HARM_PROMPT: prompt that should trigger Azure Content
31+
# Safety self-harm detection. Set in the CI secret store, not in source.
32+
# When unset, the "Input filter blocks a harmful prompt" scenario is skipped.
33+
AICORE_FILTER_TEST_MODEL=sap/gpt-4o-mini
34+
AICORE_FILTER_TEST_SELF_HARM_PROMPT=
35+
2736
# AUDITLOG
2837
CLOUD_SDK_CFG_AUDITLOG_DEFAULT_URL=https://your-auditlog-api-url-here
2938
CLOUD_SDK_CFG_AUDITLOG_DEFAULT_UAA='{"url":"https://your-auth-url","clientid":"your-client-id","clientsecret":"your-client-secret"}'

src/sap_cloud_sdk/aicore/filtering/filters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,5 +608,10 @@ def extract_filter_blocked(exc: Exception) -> ContentFilteredError | None:
608608
details=data,
609609
request_id=err.get("request_id"),
610610
)
611-
except Exception:
611+
except (ValueError, KeyError, TypeError, AttributeError):
612+
# JSON parsing failure (ValueError from json.loads), missing dict key
613+
# (KeyError), wrong shape (TypeError from .get on non-dict), or attribute
614+
# access on a non-object (AttributeError) — all mean the exception
615+
# message isn't a content-filter rejection. Let other exception types
616+
# (logic bugs in ContentFilteredError construction) surface.
612617
return None

src/sap_cloud_sdk/aicore/filtering/py.typed

Whitespace-only changes.

src/sap_cloud_sdk/aicore/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)