diff --git a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py index fde38515b..3eb316944 100644 --- a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py +++ b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py @@ -920,7 +920,7 @@ async def get_raw_document_text(document: Document) -> str: DeprecationWarning, stacklevel=2, ) - elif not (document.mime_type.startswith("text/") or document.mime_type == "application/yaml"): + elif not (document.mime_type.startswith("text/") or document.mime_type in ("application/yaml", "application/json")): raise ValueError(f"Unexpected document mime type: {document.mime_type}") if isinstance(document.content, URL): diff --git a/tests/unit/providers/agent/test_get_raw_document_text.py b/tests/unit/providers/agent/test_get_raw_document_text.py index eb481c0d8..22b120303 100644 --- a/tests/unit/providers/agent/test_get_raw_document_text.py +++ b/tests/unit/providers/agent/test_get_raw_document_text.py @@ -107,14 +107,48 @@ async def test_get_raw_document_text_deprecated_text_yaml_with_text_content_item assert "text/yaml" in str(w[0].message) +async def test_get_raw_document_text_supports_json_mime_type(): + """Test that the function accepts application/json mime type.""" + json_content = '{"name": "test", "version": "1.0", "items": ["item1", "item2"]}' + + document = Document(content=json_content, mime_type="application/json") + + result = await get_raw_document_text(document) + assert result == json_content + + +async def test_get_raw_document_text_with_json_url(): + """Test that the function handles JSON URLs correctly.""" + json_content = '{"key": "value", "list": ["item1", "item2"]}' + + with patch("llama_stack.providers.inline.agents.meta_reference.agent_instance.load_data_from_url") as mock_load: + mock_load.return_value = json_content + + document = Document(content=URL(uri="https://example.com/data.json"), mime_type="application/json") + + result = await get_raw_document_text(document) + assert result == json_content + mock_load.assert_called_once_with("https://example.com/data.json") + + +async def test_get_raw_document_text_with_json_text_content_item(): + """Test that the function handles JSON TextContentItem correctly.""" + json_content = '{"key": "value", "nested": {"array": [1, 2, 3]}}' + + document = Document(content=TextContentItem(text=json_content), mime_type="application/json") + + result = await get_raw_document_text(document) + assert result == json_content + + async def test_get_raw_document_text_rejects_unsupported_mime_types(): """Test that the function rejects unsupported mime types.""" document = Document( content="Some content", - mime_type="application/json", # Not supported + mime_type="application/pdf", # Not supported ) - with pytest.raises(ValueError, match="Unexpected document mime type: application/json"): + with pytest.raises(ValueError, match="Unexpected document mime type: application/pdf"): await get_raw_document_text(document)