{"record":{"id":"8b74472b51bbaba4","repo":"microsoft/autogen","slug":"invalid-topic-id-topic-id","errorCode":null,"errorMessage":"Invalid topic id: {topic_id}","messagePattern":"Invalid topic id: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_topic.py","lineNumber":45,"sourceCode":"    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        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        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":48,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_topic.py#L27-L48","documentation":"TopicId.from_str() parses strings of the exact form 'type/source' (maxsplit=1, so the source may itself contain slashes). If the string has no '/' at all, split yields one item and from_str raises ValueError with the offending string. This is the inverse of TopicId.__str__, so any string that did not come from str(TopicId) is suspect.","triggerScenarios":"`TopicId.from_str(\"my_topic\")` (no slash), `TopicId.from_str(\"\")`, or parsing a config/env value that holds a bare topic type instead of a full topic id. Note 'a/b/c' is valid — source becomes 'b/c'.","commonSituations":"Config files storing just the topic type where the code expects type/source; joining values with a different delimiter ('.' or ':') and parsing with from_str; hand-written topic strings in tests or CLI args.","solutions":["Provide the string in 'type/source' form: `TopicId.from_str(\"orders/created\")`.","If you only have a type, construct directly: `TopicId(\"orders\", source)` with an explicit source.","Validate input with `'/' in value` before calling from_str and fail with a clear config error."],"exampleFix":"# before\ntopic = TopicId.from_str(\"orders.created\")  # ValueError: Invalid topic id\n\n# after\ntopic = TopicId.from_str(\"orders.created/order-service\")  # type='orders.created', source='order-service'","handlingStrategy":"validation","validationCode":"def parse_topic_id(s: str) -> TopicId:\n    if \"/\" not in s:\n        raise ValueError(f\"expected 'type/source', got {s!r}\")\n    return TopicId.from_str(s)","typeGuard":"def looks_like_topic_id_str(s: str) -> bool:\n    return isinstance(s, str) and \"/\" in s","tryCatchPattern":"try:\n    topic = TopicId.from_str(raw)\nexcept ValueError:\n    topic = TopicId(raw, default_source)  # treat the raw value as a bare type","preventionTips":["Round-trip topic ids via str(TopicId(...)) when persisting so they always parse back.","Document config fields as 'type/source' and validate with a '/'-contains check at load time."],"tags":["python","autogen-core","topics","parsing","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}