observation edge cases

This commit is contained in:
phernandez
2024-12-21 17:24:47 -06:00
parent 94e55096bb
commit 99be6d36e6
3 changed files with 140 additions and 74 deletions
@@ -27,10 +27,24 @@ class Observation(BaseModel):
if not content.strip():
return None
# Basic UTF-8 validation
try:
if "\xff" in content or "\xfe" in content:
return None
if not content.isprintable():
return None
except UnicodeError:
return None
# Break up extremely long content
if len(content) > 10000: # Arbitrary large limit
logger.warning("Content too long, truncating: %s", content[:100])
return None
# Check for unclosed category first
if "[" in content and "]" not in content:
raise ParseError("unclosed category")
# Then check for missing category
match = re.match(r"^\s*(?:-\s*)?\[([^\]]*)\](.*)", content)
if not match:
@@ -69,4 +83,4 @@ class Observation(BaseModel):
raise
except Exception:
logger.exception("Failed to parse observation: %s", content)
return None
return None