Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

security: Enable Content Safety indirect attacks rule

Clémence Lesnée7f431de0a52
diff --git a/bicep/app.bicep b/bicep/app.bicep
index 5754ab3..ae78a1e 100644
--- a/bicep/app.bicep
+++ b/bicep/app.bicep
@@ -540,6 +540,13 @@ resource contentfilter 'Microsoft.CognitiveServices/accounts/raiPolicies@2024-04
basePolicyName: 'Microsoft.Default'
mode: 'Default'
contentFilters: [
+ // Indirect attacks
+ {
+ blocking: true
+ enabled: true
+ name: 'indirect_attack'
+ source: 'Prompt'
+ }
// Jailbreak
{
blocking: true
diff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.py
index 2e4ce9e..3d4d244 100644
--- a/helpers/config_models/prompts.py
+++ b/helpers/config_models/prompts.py
@@ -1,6 +1,7 @@
from azure.core.exceptions import HttpResponseError
from datetime import datetime, UTC
from functools import cached_property
+from html import escape
from logging import Logger
from models.call import CallStateModel
from models.message import MessageModel
@@ -464,10 +465,13 @@ class LlmModel(BaseModel):
# Format trainings, if any
if trainings:
- trainings_str = (
- TypeAdapter(list[TrainingModel])
- .dump_json(trainings, exclude=TrainingModel.excluded_fields_for_llm())
- .decode()
+ # Format documents for Content Safety scan compatibility
+ # See: https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/content-filter?tabs=warning%2Cpython-new#embedding-documents-in-your-prompt
+ trainings_str = "\n".join(
+ [
+ f"<documents>{escape(training.model_dump_json(exclude=TrainingModel.excluded_fields_for_llm()))}</documents>"
+ for training in trainings
+ ]
)
res += "\n\n# Trusted data you can use"
res += f"\n{trainings_str}"
diff --git a/helpers/llm_tools.py b/helpers/llm_tools.py
index ea15da9..096b962 100644
--- a/helpers/llm_tools.py
+++ b/helpers/llm_tools.py
@@ -11,10 +11,11 @@ from models.message import (
PersonaEnum as MessagePersonaEnum,
StyleEnum as MessageStyleEnum,
)
+from html import escape
from models.reminder import ReminderModel
from models.training import TrainingModel
from openai.types.chat import ChatCompletionToolParam
-from pydantic import TypeAdapter, ValidationError
+from pydantic import ValidationError
from typing import Awaitable, Callable, Annotated, Literal
from typing_extensions import TypedDict
import asyncio
@@ -335,10 +336,13 @@ class LlmPlugins:
)
# Flatten, remove duplicates, and sort by score
trainings = sorted(set(training for task in tasks for training in task or []))
- trainings_str = (
- TypeAdapter(list[TrainingModel])
- .dump_json(trainings, exclude=TrainingModel.excluded_fields_for_llm())
- .decode()
+ # Format documents for Content Safety scan compatibility
+ # See: https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/content-filter?tabs=warning%2Cpython-new#embedding-documents-in-your-prompt
+ trainings_str = "\n".join(
+ [
+ f"<documents>{escape(training.model_dump_json(exclude=TrainingModel.excluded_fields_for_llm()))}</documents>"
+ for training in trainings
+ ]
)
# Format results
res = "# Search results"