python1from dataclasses import dataclass 2from typing import List, Optional 3from enum import Enum 4from datetime import datetime 5 6class TurnRole(Enum): 7 USER = "user" 8 ASSISTANT = "assistant" 9 SYSTEM = "system" 10 11@dataclass 12class ConversationTurn: 13 role: TurnRole 14 content: str 15 timestamp: datetime 16 turn_number: int 17 validated_instructions: Optional[str] = None 18 19@dataclass 20class ConversationPolicy: 21 """Defines immutable rules for the conversation""" 22 system_instructions: str 23 allowed_functions: List[str] 24 max_turns: int 25 26def validate_turn(turn: ConversationTurn, policy: ConversationPolicy) -> bool: 27 """ 28 Validates a turn against the conversation policy. 29 30 Args: 31 turn (ConversationTurn): The current turn to be validated. 32 policy (ConversationPolicy): The immutable rules of the conversation. 33 34 Returns: 35 bool: True if the turn is valid according to the policy, False otherwise. 36 37[Read the full article at Towards AI - Medium](https://pub.towardsai.net/the-five-horsemen-of-prompt-injection-a-technical-deep-dive-into-llm-attack-vectors-56b7b9f6cbab?source=rss----98111c9905da---4) 38 39--- 40 41**Want to create content about this topic?** [Use Nemati AI tools](https://nemati.ai) to generate articles, social posts, and more.
AI & Machine Learning
Ali Nemati6 hours ago
The Five Horsemen of Prompt Injection: A Technical Deep Dive into LLM Attack Vectors
46 sec read4 views0 listens
<h3>Prevention Mechanism: Conversation Policy Enforcement with State Validation</h3>
<p><strong>Strategy</strong>: Explicitly track and re-validate the conversation state and policy at each turn.</p>
4
Ali NematiWritten by Ali

![[AINews] The Unreasonable Effectiveness of Closing the Loop](/_next/image?url=https%3A%2F%2Fmedia.nemati.ai%2Fmedia%2Fblog%2Fimages%2Farticles%2F600e22851bc7453b.webp&w=3840&q=75)



