Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

fix(core): template generator chat prompt

dextmorgnaf590675ec7b
diff --git a/flowsint-core/src/flowsint_core/core/services/chat_service.py b/flowsint-core/src/flowsint_core/core/services/chat_service.py
index 331d2633..2f66787b 100644
--- a/flowsint-core/src/flowsint_core/core/services/chat_service.py
+++ b/flowsint-core/src/flowsint_core/core/services/chat_service.py
@@ -26,20 +26,6 @@ DEFAULT_SYSTEM_PROMPT = (
)
-def clean_context(context: List[Dict]) -> List[Dict]:
- """Remove unnecessary keys from context data."""
- cleaned = []
- for item in context:
- if isinstance(item, dict):
- cleaned_item = item.get("data", item).copy()
- cleaned_item.pop("id", None)
- cleaned_item.pop("sketch_id", None)
- if "data" in cleaned_item and isinstance(cleaned_item["data"], dict):
- cleaned_item["data"].pop("sketch_id", None)
- cleaned_item.pop("measured", None)
- cleaned.append(cleaned_item)
- return cleaned
-
class ChatService(BaseService):
"""
@@ -153,15 +139,10 @@ class ChatService(BaseService):
) -> Dict[str, Any]:
context_message = None
if context:
- try:
- cleaned_context = clean_context(context)
- if cleaned_context:
- context_str = ";".join(context)
- context_message = f"Context: {context_str}"
- if len(context_message) > 2000:
- context_message = context_message[:2000] + "..."
- except Exception as e:
- print(f"Context processing error: {e}")
+ context_str = "; ".join(context)
+ context_message = f"Context: {context_str}"
+ if len(context_message) > 2000:
+ context_message = context_message[:2000] + "..."
sorted_messages = sorted(chat.messages, key=lambda x: x.created_at)
recent_messages = (
diff --git a/flowsint-core/src/flowsint_core/core/services/template_generator_service.py b/flowsint-core/src/flowsint_core/core/services/template_generator_service.py
index 31b65064..66945d4d 100644
--- a/flowsint-core/src/flowsint_core/core/services/template_generator_service.py
+++ b/flowsint-core/src/flowsint_core/core/services/template_generator_service.py
@@ -127,6 +127,7 @@ response:
- Use realistic field mappings based on common API response structures.
- If the API likely requires authentication, include a `secrets` section.
- Keep the template simple and focused on what the user asked for.
+- IMPORTANT: Always quote values that contain {{...}} placeholders, e.g. `x-apikey: "{{secrets.API_KEY}}"`. Unquoted curly braces are invalid YAML.
"""
@@ -139,6 +140,16 @@ def _extract_yaml(text: str) -> str:
return text.strip()
+def _quote_template_placeholders(yaml_str: str) -> str:
+ """Quote unquoted {{...}} placeholders that would break YAML parsing."""
+ return re.sub(
+ r"(:\s+)(\{\{[^}]+\}\})\s*$",
+ r'\1"\2"',
+ yaml_str,
+ flags=re.MULTILINE,
+ )
+
+
class TemplateGeneratorService(BaseService):
"""Generates enricher template YAML from a free-text prompt using an LLM."""
@@ -175,6 +186,7 @@ class TemplateGeneratorService(BaseService):
response = await provider.complete(messages)
yaml_str = _extract_yaml(response)
+ yaml_str = _quote_template_placeholders(yaml_str)
# Validate the YAML
try: