Enhance exercise_ai module with skill input sanitization and version update
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 38s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m16s

- Introduced a new constant `_MAX_SANITIZE_SKILL_INPUT_ROWS` to limit the number of skill entries processed, improving performance and preventing issues with excessively long skill arrays.
- Updated the `_extract_json_array` and `_sanitize_skill_entries` functions to enforce this limit, ensuring that only a maximum of 250 skill entries are handled and that processing stops after 5 valid entries.
- Incremented the application version to 0.8.155 and updated the changelog to reflect these changes, including a note on the improvements made to the AI endpoint for skill arrays.
This commit is contained in:
Lars committed 2026-05-22 09:59:56 +02:00
1 parent 286c36e9d7
commit 9be69ace5c
2 files changed
+24 -5

No files matched your search

+15 -3
View File
@@ -34,6 +34,7 @@ _TOKEN_FIND = re.compile(r"[a-zäöüß0-9]+", re.IGNORECASE)
_MAX_PLAIN_FIELD = 28_000
_MAX_SKILLS_CATALOG_LINES = 240
_MAX_SUMMARY_CHARS = 220
_MAX_SANITIZE_SKILL_INPUT_ROWS = 250
_FALLBACK_RETRIEVAL_CONFIG: Dict[str, Any] = {
"version": 1,
@@ -514,23 +515,34 @@ def _extract_json_array(text: str) -> Any:
end = s.rfind("]")
if end > 0:
s = s[: end + 1]
return json.loads(s)
parsed = json.loads(s)
if isinstance(parsed, list) and len(parsed) > _MAX_SANITIZE_SKILL_INPUT_ROWS:
parsed = parsed[:_MAX_SANITIZE_SKILL_INPUT_ROWS]
return parsed
if s.startswith("{"):
obj = json.loads(s)
if isinstance(obj, dict):
for k in ("skills", "items", "data"):
v = obj.get(k)
if isinstance(v, list):
if len(v) > _MAX_SANITIZE_SKILL_INPUT_ROWS:
return v[:_MAX_SANITIZE_SKILL_INPUT_ROWS]
return v
raise ValueError("JSON-Objekt ohne Skills-Liste")
return json.loads(s)
parsed_end = json.loads(s)
if isinstance(parsed_end, list) and len(parsed_end) > _MAX_SANITIZE_SKILL_INPUT_ROWS:
return parsed_end[:_MAX_SANITIZE_SKILL_INPUT_ROWS]
return parsed_end
def _sanitize_skill_entries(cur, rows: Any) -> List[Dict[str, Any]]:
if not isinstance(rows, list):
return []
out: List[Dict[str, Any]] = []
for raw in rows:
cap = rows[:_MAX_SANITIZE_SKILL_INPUT_ROWS]
for raw in cap:
if len(out) >= 5:
break
if not isinstance(raw, dict):
continue
sid = raw.get("skill_id")