Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

🔒️(summary) sanitize LLM failures and summary progress logs

Florent Chehab3cd2cb5591bf
diff --git a/src/summary/summary/core/celery_worker.py b/src/summary/summary/core/celery_worker.py
index c1ee5ce2..c40562c3 100644
--- a/src/summary/summary/core/celery_worker.py
+++ b/src/summary/summary/core/celery_worker.py
@@ -311,6 +311,17 @@ def format_actions(llm_output: dict) -> str:
return ""
+def parse_llm_json(value: str) -> dict:
+ """Parse an LLM response without exposing it in decoding errors."""
+ try:
+ result = json.loads(value)
+ if not isinstance(result, dict):
+ raise ValueError
+ return result
+ except (TypeError, ValueError):
+ raise LLMException("Invalid LLM response") from None
+
+
def summarize_transcription_internals(
*, distinct_id: str, transcript: str, session_id: str
) -> str:
@@ -351,13 +362,13 @@ def summarize_transcription_internals(
)
logger.info("Plan generated")
- res = json.loads(parts)
+ res = parse_llm_json(parts)
parts = res.get("titles", [])
- logger.info("Parts to summarize: %s", parts)
+ logger.info("Parts to summarize: %s", len(parts))
parts_summarized = []
- for part in parts:
+ for i, part in enumerate(parts):
prompt_user_part = PROMPT_USER_PART.format(part=part, transcript=transcript)
- logger.info("Summarizing part: %s", part)
+ logger.info("Summarizing part %s", i + 1)
parts_summarized.append(
llm_service.call(PROMPT_SYSTEM_PART, prompt_user_part, name="part")
)
@@ -373,7 +384,7 @@ def summarize_transcription_internals(
response_format=FORMAT_NEXT_STEPS,
)
- next_steps = format_actions(json.loads(next_steps))
+ next_steps = format_actions(parse_llm_json(next_steps))
logger.info("Next steps generated")
diff --git a/src/summary/summary/core/llm_service.py b/src/summary/summary/core/llm_service.py
index e8b52b0c..08c3822b 100644
--- a/src/summary/summary/core/llm_service.py
+++ b/src/summary/summary/core/llm_service.py
@@ -140,6 +140,6 @@ class LLMService:
response = self._client.chat.completions.create(**params)
return response.choices[0].message.content
- except Exception as e:
- logger.exception("LLM call failed: %s", e)
- raise LLMException(f"LLM call failed: {e}") from e
+ except Exception:
+ logger.error("LLM call failed")
+ raise LLMException("LLM call failed") from None
diff --git a/src/summary/tests/unit/test_privacy.py b/src/summary/tests/unit/test_privacy.py
index 044f4278..8f5a0a0b 100644
--- a/src/summary/tests/unit/test_privacy.py
+++ b/src/summary/tests/unit/test_privacy.py
@@ -6,7 +6,8 @@ from unittest.mock import Mock
import pytest
import requests
-from summary.core import analytics, webhook_service
+from summary.core import analytics, celery_worker, webhook_service
+from summary.core.llm_service import LLMException, LLMService
from summary.core.privacy import redact_url
from summary.core.shared_models import SummarizeWebhookSuccessPayload
@@ -19,6 +20,19 @@ def test_url_redaction():
assert redact_url(URL) == "https://example.com/file?[redacted]"
+def test_llm_exception_does_not_include_upstream_message(caplog):
+ """LLM failures retain their category without logging upstream text."""
+ observability = Mock(is_enabled=False)
+ observability.get_openai_client.return_value.chat.completions.create.side_effect = (
+ ValueError(CANARY)
+ )
+ with caplog.at_level(logging.DEBUG), pytest.raises(LLMException) as exc:
+ LLMService(observability).call("system", CANARY, "test")
+ assert CANARY not in str(exc.value)
+ assert CANARY not in caplog.text
+ assert exc.value.__suppress_context__
+
+
@pytest.mark.parametrize("log_level", [logging.DEBUG, logging.INFO])
def test_webhook_content_is_only_logged_at_debug(
monkeypatch, caplog, settings_override, log_level
@@ -88,6 +102,14 @@ def test_analytics_source_url_removes_signature():
assert CANARY not in str(metadata)
+def test_invalid_llm_json_is_sanitized():
+ """Invalid structured LLM output retains a retryable LLM category."""
+ with pytest.raises(LLMException) as exc:
+ celery_worker.parse_llm_json(CANARY)
+ assert CANARY not in str(exc.value)
+ assert exc.value.__suppress_context__
+
+
@pytest.mark.parametrize(
("url", "expected"),
[