-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfallback.py
More file actions
42 lines (31 loc) · 1.11 KB
/
fallback.py
File metadata and controls
42 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Nodo 3: Fallback Inicial - Initial fallback processing."""
import logging
from app.agents.state import AgentState
from langchain_core.messages import SystemMessage
from langchain_openai import ChatOpenAI
logger = logging.getLogger(__name__)
llm = ChatOpenAI(
model="gpt-5-nano",
)
# TO DO: implementar clase nodo fallback y inicializar el llm en el init
def fallback(state: AgentState) -> AgentState:
"""
Fallback node - Performs fallback processing.
This node:
1. Alerts about malicious prompt
2. Generates an error_message from llm to show the user
Args:
state: Agent state containing the prompt or initial context
Returns:
error_message
"""
logger.warning(
"Defensive check triggered: Malicious prompt detected"
)
messages = [
SystemMessage(
content="Your job is to generate an error message in user's language for the user explaining the database doesn't have the information to respond what the user asked"
)
] + state["messages"]
error_message = llm.invoke(messages)
return {"messages": [error_message]}