forked from cardosofelipe/fast-next-template
refactor(safety): apply consistent formatting across services and tests
Improved code readability and uniformity by standardizing line breaks, indentation, and inline conditions across safety-related services, models, and tests, including content filters, validation rules, and emergency controls.
This commit is contained in:
@@ -260,9 +260,15 @@ class ContentFilter:
|
||||
continue
|
||||
if pattern.category == ContentCategory.SECRETS and not enable_secret_filter:
|
||||
continue
|
||||
if pattern.category == ContentCategory.CREDENTIALS and not enable_secret_filter:
|
||||
if (
|
||||
pattern.category == ContentCategory.CREDENTIALS
|
||||
and not enable_secret_filter
|
||||
):
|
||||
continue
|
||||
if pattern.category == ContentCategory.INJECTION and not enable_injection_filter:
|
||||
if (
|
||||
pattern.category == ContentCategory.INJECTION
|
||||
and not enable_injection_filter
|
||||
):
|
||||
continue
|
||||
self._patterns.append(replace(pattern))
|
||||
|
||||
@@ -343,7 +349,10 @@ class ContentFilter:
|
||||
filtered_content = content
|
||||
for match in all_matches:
|
||||
matched_pattern = self._get_pattern(match.pattern_name)
|
||||
if matched_pattern and matched_pattern.action in (FilterAction.REDACT, FilterAction.BLOCK):
|
||||
if matched_pattern and matched_pattern.action in (
|
||||
FilterAction.REDACT,
|
||||
FilterAction.BLOCK,
|
||||
):
|
||||
filtered_content = (
|
||||
filtered_content[: match.start_pos]
|
||||
+ (match.redacted_text or "[REDACTED]")
|
||||
@@ -371,8 +380,12 @@ class ContentFilter:
|
||||
if raise_on_block:
|
||||
raise ContentFilterError(
|
||||
block_reason or "Content blocked",
|
||||
filter_type=all_matches[0].category.value if all_matches else "unknown",
|
||||
detected_patterns=[m.pattern_name for m in all_matches] if all_matches else [],
|
||||
filter_type=all_matches[0].category.value
|
||||
if all_matches
|
||||
else "unknown",
|
||||
detected_patterns=[m.pattern_name for m in all_matches]
|
||||
if all_matches
|
||||
else [],
|
||||
)
|
||||
elif all_matches:
|
||||
logger.debug(
|
||||
@@ -480,9 +493,13 @@ class ContentFilter:
|
||||
matches = pattern.find_matches(content)
|
||||
for match in matches:
|
||||
if pattern.action == FilterAction.BLOCK:
|
||||
issues.append(f"Blocked: {pattern.name} at position {match.start_pos}")
|
||||
issues.append(
|
||||
f"Blocked: {pattern.name} at position {match.start_pos}"
|
||||
)
|
||||
elif pattern.action == FilterAction.WARN and not allow_warnings:
|
||||
issues.append(f"Warning: {pattern.name} at position {match.start_pos}")
|
||||
issues.append(
|
||||
f"Warning: {pattern.name} at position {match.start_pos}"
|
||||
)
|
||||
|
||||
return len(issues) == 0, issues
|
||||
|
||||
|
||||
Reference in New Issue
Block a user