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
Validating ParsedMedia.data is not empty
  • Loading branch information
jamesbraza committed Jan 16, 2026
commit 574adea73e91d1437e373911e37733df0b0c2ced
4 changes: 3 additions & 1 deletion src/paperqa/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,9 @@ class ParsedMedia(BaseModel):
bytes,
PlainSerializer(bytes_to_string),
BeforeValidator(lambda x: x if isinstance(x, bytes) else string_to_bytes(x)),
] = Field(description="Raw image, ideally directly savable to a PNG image.")
] = Field(
min_length=1, description="Raw image, ideally directly savable to a PNG image."
)
text: str | None = Field(
default=None,
description=(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,11 @@ def test_media_to_image_url(subtests: SubTests) -> None:
assert "image/png" in url


def test_parsed_media_empty_data_raises() -> None:
with pytest.raises(ValidationError, match="at least 1 byte"):
ParsedMedia(index=0, data=b"")


@pytest.mark.asyncio
async def test_image_aggregation(stub_data_dir: Path) -> None:
png_path = stub_data_dir / "sf_districts.png"
Expand Down
Loading