mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-05 14:32:20 +02:00
fix: taint prefetched web context
This commit is contained in:
+10
-2
@@ -61,7 +61,12 @@ def _sanitize_label(label: str) -> str:
|
||||
return label
|
||||
|
||||
|
||||
def untrusted_context_message(label: str, content: Any) -> Dict[str, Any]:
|
||||
def untrusted_context_message(
|
||||
label: str,
|
||||
content: Any,
|
||||
*,
|
||||
provenance_origin: str | None = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""Return an LLM message that keeps retrieved/source text out of system role.
|
||||
|
||||
The template is structured so that *only* the hardcoded
|
||||
@@ -73,6 +78,9 @@ def untrusted_context_message(label: str, content: Any) -> Dict[str, Any]:
|
||||
safe_label = _sanitize_label(label)
|
||||
text = "" if content is None else str(content)
|
||||
text = _escape_guard_markers(text)
|
||||
metadata: Dict[str, Any] = {"trusted": False, "source": label}
|
||||
if provenance_origin:
|
||||
metadata["provenance_origin"] = provenance_origin
|
||||
return {
|
||||
"role": "user",
|
||||
"content": (
|
||||
@@ -82,5 +90,5 @@ def untrusted_context_message(label: str, content: Any) -> Dict[str, Any]:
|
||||
f"{text}\n"
|
||||
f"{GUARD_CLOSE}"
|
||||
),
|
||||
"metadata": {"trusted": False, "source": label},
|
||||
"metadata": metadata,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user