Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions hindsight-api-slim/hindsight_api/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ class MemoryItem(BaseModel):
description="Optional tags for visibility scoping. Memories with tags can be filtered during recall.",
)

@field_validator("content")
@classmethod
def validate_content(cls, v: str) -> str:
if not v.strip():
raise ValueError("content cannot be empty")
return v

@field_validator("tags", mode="before")
@classmethod
def coerce_tags(cls, v):
Expand Down
15 changes: 15 additions & 0 deletions hindsight-api-slim/tests/test_none_llm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ async def test_http_retain_works(none_api_client):
assert response.status_code == 200


@pytest.mark.asyncio
@pytest.mark.parametrize("content", ["", " \n\t"])
async def test_http_retain_rejects_blank_content(none_api_client, content):
"""Retain endpoint should reject empty or whitespace-only content."""
bank_id = f"test_none_http_retain_blank_{datetime.now(timezone.utc).timestamp()}"

response = await none_api_client.post(
f"/v1/default/banks/{bank_id}/memories",
json={"items": [{"content": content, "context": "test"}]},
)

assert response.status_code == 422
assert "content cannot be empty" in str(response.json()["detail"])


@pytest.mark.asyncio
async def test_http_recall_works(none_api_client):
"""Recall endpoint should work with provider=none."""
Expand Down