tessl install tessl/pypi-josepy@2.1.0JOSE protocol implementation in Python with support for JSON Web Algorithms, Keys, and Signatures
Agent Success
Agent success rate when using this tile
73%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.16x
Baseline
Agent success rate without this tile
63%
Define JSON-serializable message models that use a type field to select the correct subclass when deserializing, while safely handling unknown or missing types. The type value error maps to ErrorMessage and info maps to InfoMessage, and that field must always be present in serialized output.
{"type": "error", "content": "Failed", "code": 500, "detail": "DB down"}, Message.from_json returns an ErrorMessage instance with matching attributes. @testtype value, Message.from_json raises a descriptive exception mentioning that type value. @testtype field, Message.from_json raises a descriptive exception about the missing type field. @testInfoMessage with to_json and deserializing it with Message.from_json preserves the type of info and subclass-specific fields such as level and content. @test@generates
from typing import Any, Dict
class Message:
message_type: str
@classmethod
def from_json(cls, payload: Dict[str, Any]) -> "Message":
...
def to_json(self) -> Dict[str, Any]:
...
class ErrorMessage(Message):
message_type: str = "error"
content: str
code: int
detail: str
class InfoMessage(Message):
message_type: str = "info"
content: str
level: strProvides declarative JSON field definitions and type-based object dispatching utilities.