Files
Core_Be/AI/ModificationGuard.cs
T
Dhananjaya99 bffc9b1686 first commit
2026-09-28 11:44:26 +05:30

48 lines
1.2 KiB
C#

namespace Fitness_core_BE.AI
{
public class ModificationGuard
{
private static readonly string[] AllowedKeywords =
{
"replace",
"remove",
"allergy",
"change",
"vegetarian",
"calorie",
"protein",
"carb",
"fat",
"meal",
"ingredient"
};
private static readonly string[] BlockedPatterns =
{
"ignore previous instructions",
"system prompt",
"act as",
"bypass",
"developer mode",
"jailbreak"
};
public void Validate(string message)
{
if (string.IsNullOrWhiteSpace(message))
throw new Exception("Modification cannot be empty.");
if (message.Length > 500)
throw new Exception("Modification too long.");
var lower = message.ToLower();
if (BlockedPatterns.Any(p => lower.Contains(p)))
throw new Exception("Invalid modification request.");
//if (!AllowedKeywords.Any(k => lower.Contains(k)))
// throw new Exception("Only meal plan modifications are allowed.");
}
}
}