{"record":{"id":"81a8183873e2d102","repo":"microsoft/semantic-kernel","slug":"invalid-topic-type-self-type-must-match-the-pa","errorCode":null,"errorMessage":"Invalid topic type: {self.type}. Must match the pattern: ^[\\w\\-\\.\\:\\=]+\\Z","messagePattern":"Invalid topic type: (.+?)\\. Must match the pattern: \\^\\[\\\\w\\\\-\\\\\\.\\\\:\\\\=\\]\\+\\\\Z","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/runtime/core/topic.py","lineNumber":45,"sourceCode":"\n    type: str\n    \"\"\"Type of the event that this topic_id contains. Adhere's to the cloud event spec.\n\n    Must match the pattern: ^[\\\\w\\\\-\\\\.\\\\:\\\\=]+\\\\Z\n\n    Learn more here: https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#type\n    \"\"\"\n\n    source: str\n    \"\"\"Identifies the context in which an event happened. Adhere's to the cloud event spec.\n\n    Learn more here: https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#source-1\n    \"\"\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Validate the topic type and source.\"\"\"\n        if is_valid_topic_type(self.type) is False:\n            raise ValueError(f\"Invalid topic type: {self.type}. Must match the pattern: ^[\\\\w\\\\-\\\\.\\\\:\\\\=]+\\\\Z\")\n\n    def __str__(self) -> str:\n        \"\"\"Convert the TopicId to a string.\"\"\"\n        return f\"{self.type}/{self.source}\"\n\n    @classmethod\n    def from_str(cls, topic_id: str) -> Self:\n        \"\"\"Convert a string of the format ``type/source`` into a TopicId.\"\"\"\n        items = topic_id.split(\"/\", maxsplit=1)\n        if len(items) != 2:\n            raise ValueError(f\"Invalid topic id: {topic_id}\")\n        type, source = items[0], items[1]\n        return cls(type, source)\n","sourceCodeStart":27,"sourceCodeEnd":59,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/core/topic.py#L27-L59","documentation":"Raised by TopicId.__post_init__ when the 'type' field fails the regex ^[\\w\\-\\.\\:\\=]+\\Z (one or more of: word characters, hyphen, dot, colon, equals). An empty type, or one containing any other character (space, slash, @, etc.), raises ValueError. The pattern follows the CloudEvents type spec.","triggerScenarios":"Constructing TopicId(type, source) where type contains disallowed characters (space, '/', '@', etc.) or is an empty string; deriving the type from free-form input or file paths that include '/'.","commonSituations":"Deriving topic type from user input, URLs, or file paths containing slashes/spaces; empty topic type from a missing config value.","solutions":["Sanitize the type string so it matches ^[\\w\\-\\.\\:\\=]+$.","Replace disallowed characters (e.g. '/' -> '.' or '_', ' ' -> '_').","Validate with is_valid_topic_type before constructing TopicId."],"exampleFix":"// before\ntopic = TopicId(type='com.example/requests', source='abc')  # '/' not allowed -> ValueError\n\n// after\nfrom semantic_kernel.agents.runtime.core.topic import is_valid_topic_type\ntype_str = 'com.example.requests'  # sanitized\nassert is_valid_topic_type(type_str)\ntopic = TopicId(type=type_str, source='abc')","handlingStrategy":"validation","validationCode":"import re\nfrom semantic_kernel.agents.runtime.core.topic import is_valid_topic_type\n\ndef safe_topic_type(value: str) -> str:\n    cleaned = re.sub(r'[^\\w\\-.\\:=]', '.', value)\n    if not cleaned or not is_valid_topic_type(cleaned):\n        raise ValueError('topic type is empty or still invalid after sanitization')\n    return cleaned","typeGuard":"from semantic_kernel.agents.runtime.core.topic import is_valid_topic_type\n\ndef is_valid_topic(t: str) -> bool:\n    return is_valid_topic_type(t)","tryCatchPattern":null,"preventionTips":["Validate topic type with is_valid_topic_type before constructing TopicId.","Sanitize slashes/spaces/at-signs out of user-derived type strings.","Reject empty topic types at the config boundary."],"tags":["topic","validation","cloud-events"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}