{"record":{"id":"98ed2aa82c8d8a73","repo":"agentscope-ai/agentscope","slug":"exactly-one-of-data-or-url-must-be-provided","errorCode":null,"errorMessage":"Exactly one of `data` or `url` must be provided.","messagePattern":"Exactly one of `data` or `url` must be provided\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/event/_event.py","lineNumber":387,"sourceCode":"    \"\"\"Event type.\"\"\"\n    reply_id: str\n    \"\"\"ID of the reply message this tool result belongs to.\"\"\"\n    tool_call_id: str\n    \"\"\"ID of the corresponding tool call.\"\"\"\n    block_id: str = Field(default_factory=_generate_id)\n    \"\"\"Unique identifier of the data block created by this event.\"\"\"\n    media_type: str\n    \"\"\"MIME type of the binary content.\"\"\"\n    data: str | None = None\n    \"\"\"Base64-encoded binary data, mutually exclusive with `url`.\"\"\"\n    url: str | None = None\n    \"\"\"URL pointing to the binary content, mutually exclusive with `data`.\"\"\"\n\n    @model_validator(mode=\"after\")\n    def validate_data_source(self) -> Self:\n        \"\"\"Ensure exactly one data source is provided.\"\"\"\n        if (self.data is None) == (self.url is None):\n            raise ValueError(\n                \"Exactly one of `data` or `url` must be provided.\",\n            )\n        return self\n\n\nclass ToolResultEndEvent(EventBase):\n    \"\"\"Tool result end event.\"\"\"\n\n    model_config = ConfigDict(use_enum_values=True)\n\n    type: Literal[EventType.TOOL_RESULT_END] = EventType.TOOL_RESULT_END\n    \"\"\"Event type.\"\"\"\n    reply_id: str\n    \"\"\"ID of the reply message this tool result belongs to.\"\"\"\n    tool_call_id: str\n    \"\"\"ID of the corresponding tool call.\"\"\"\n    state: ToolResultState\n    \"\"\"Final execution state of the tool call.\"\"\"","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/event/_event.py#L369-L405","documentation":"A pydantic model_validator on the event model enforces that binary content carries exactly one of `data` (inline bytes) or `url` (remote reference). Both set, or both None, makes the model invalid at construction time.","triggerScenarios":"Constructing the event with neither data nor url, or with both populated: Event(data=raw, url=\"https://...\"). The (data is None) == (url is None) check rejects either case during model validation.","commonSituations":"Conditionally building kwargs and accidentally passing data=None alongside a url (or url=\"\" which is not None); copy/pasting event payloads; LLM-generated tool results that fill both fields.","solutions":["Set exactly one field; for the other, omit it entirely rather than passing None explicitly","Sanitize kwargs before construction: drop keys whose value is None","If you intended inline bytes plus metadata, put metadata in a different field, not url"],"exampleFix":"# before\nev = EventBaseSubclass(data=None, url=\"https://example.com/x.png\")  # both None-ness mismatch? no: data None + url set is OK\n# actual failing cases:\nev = Event(data=b\"...\", url=\"https://...\")   # both set\nev = Event()                                  # neither set\n\n# after\nev = Event(url=\"https://example.com/x.png\")   # exactly one","handlingStrategy":"validation","validationCode":"payload = {k: v for k, v in ((\"data\", data), (\"url\", url)) if v is not None}\nassert len(payload) == 1, \"provide exactly one of data/url\"","typeGuard":"def is_valid_source_pair(data, url) -> bool:\n    return (data is None) != (url is None)","tryCatchPattern":"try:\n    ev = Event(data=data, url=url)\nexcept ValueError as e:\n    if \"Exactly one of\" in str(e):\n        ev = Event(url=url) if url else Event(data=data)\n    else:\n        raise","preventionTips":["Omit the unused field instead of passing None explicitly","Note url=\"\" is not None and still counts as set","Drop None-valued keys when building kwargs dynamically"],"tags":["pydantic","event","validation","mutually-exclusive"],"backgroundTag":"schema-validation-failed","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}