Allow long relation_type values in responses

Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
phernandez
2026-03-28 09:56:22 -05:00
parent a4e0422926
commit 01cbad1dbe
3 changed files with 79 additions and 2 deletions
+7 -2
View File
@@ -178,8 +178,13 @@ ContentType = Annotated[
]
RelationType = Annotated[str, MinLen(1), MaxLen(200)]
"""Type of relationship between entities. Always use active voice present tense."""
RelationType = Annotated[str, MinLen(1)]
"""Type of relationship between entities. Always use active voice present tense.
The database stores relation_type as an unrestricted string, and response models
need to tolerate existing long-form values written by LLMs. Keeping an API-only
200-character cap here causes reads to fail for valid stored data.
"""
ObservationStr = Annotated[
str,
+52
View File
@@ -137,6 +137,58 @@ async def test_get_entity_by_id(client: AsyncClient, test_graph, v2_project_url,
assert entity.api_version == "v2"
@pytest.mark.asyncio
async def test_get_entity_by_id_allows_long_relation_type(
client: AsyncClient,
v2_project_url,
relation_repository,
):
"""GET entity should not fail when stored relation_type exceeds 200 characters."""
source_response = await client.post(
f"{v2_project_url}/knowledge/entities",
json={
"title": "Long Relation Source",
"directory": "test",
"content": "Source entity content",
},
)
assert source_response.status_code == 200
source_entity = EntityResponseV2.model_validate(source_response.json())
target_response = await client.post(
f"{v2_project_url}/knowledge/entities",
json={
"title": "Long Relation Target",
"directory": "test",
"content": "Target entity content",
},
)
assert target_response.status_code == 200
target_entity = EntityResponseV2.model_validate(target_response.json())
long_relation_type = (
"**Architecture/efficiency concern:** "
"the orchestration prompt expanded a short edge label into a full descriptive note "
"that is much longer than 200 characters but should still serialize cleanly."
)
await relation_repository.create(
{
"from_id": source_entity.id,
"to_id": target_entity.id,
"to_name": target_entity.title,
"relation_type": long_relation_type,
}
)
response = await client.get(f"{v2_project_url}/knowledge/entities/{source_entity.external_id}")
assert response.status_code == 200
entity = EntityResponseV2.model_validate(response.json())
assert len(entity.relations) == 1
assert entity.relations[0].relation_type == long_relation_type
@pytest.mark.asyncio
async def test_get_entity_by_id_not_found(client: AsyncClient, v2_project_url):
"""Test getting a non-existent entity by external_id returns 404."""
+20
View File
@@ -91,6 +91,26 @@ def test_relation_response():
assert relation.context is None
def test_relation_response_allows_long_relation_type():
"""Long relation labels should round-trip because stored data has no DB length cap."""
long_relation_type = (
"**Architecture/efficiency concern:** "
"the orchestration prompt expanded a short edge label into a full descriptive note "
"that is much longer than 200 characters but still represents the stored relation type."
)
data = {
"permalink": "test/123/long/test/456",
"from_id": "test/123",
"to_id": "test/456",
"relation_type": long_relation_type,
"from_entity": {"permalink": "test/123"},
"to_entity": {"permalink": "test/456"},
}
relation = RelationResponse.model_validate(data)
assert relation.relation_type == long_relation_type
def test_relation_response_with_null_permalink():
"""Test RelationResponse handles null permalinks by falling back to file_path (fixes issue #483).