BasicReturns ships two PydanticDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dev2forge/BasicReturns/llms.txt
Use this file to discover all available pages before exploring further.
BaseModel subclasses that standardise what every function in your application returns. Both classes live in BasicReturns.main and are re-exported from the top-level BasicReturns package, so you can import them directly with from BasicReturns import BasicReturn, DataAndMsgReturn.
BasicReturn
BasicReturn is the base return model. Use it for operations that only need to signal success or failure — there is no payload to carry back, and a human-readable message is not required.
Fields
True when the operation succeeded; set to False to indicate a failure. Mirrors the semantics of an HTTP 2xx/4xx-5xx status code.The exception or error object attached to the failure. Remains
None on success. Typically holds an Exception instance, but can be any object.Methods
| Method | Return type | Description |
|---|---|---|
to_dict() | dict | Returns {"ok": self.ok, "error": self.error} |
__str__() | str | Returns 'OK: {ok}\nError: {error}' |
Example
DataAndMsgReturn
DataAndMsgReturn extends BasicReturn, inheriting both ok and error. It adds two extra fields for operations that need to return a result payload and a human-readable status message.
Fields
Inherited from
BasicReturn. True on success, False on failure.Inherited from
BasicReturn. The error object when ok is False.A human-readable message describing the outcome of the operation — useful for UI feedback or log entries.
The result payload on success. Can hold any type: a dict, list, dataclass instance, or primitive value.
to_dict() falls back to {} when this is None.Methods
| Method | Return type | Description |
|---|---|---|
to_dict() | dict | Returns {"ok", "error", "msg", "data"} — data falls back to {} if None |
__str__() | str | Returns all four fields formatted across multiple lines |
Example
Inheritance diagram
When to use which
| Situation | Recommended model |
|---|---|
| Simple write, delete, or side-effect — caller only needs to know if it worked | BasicReturn |
| Operation that returns a result value the caller will use | DataAndMsgReturn |
| Operation that surfaces messages to a UI, CLI, or log | DataAndMsgReturn |
| Chaining multiple steps where intermediate steps carry no payload | BasicReturn |
Both
BasicReturn and DataAndMsgReturn are Pydantic BaseModel subclasses, so all standard Pydantic features are available: field validation, .model_dump(), .model_validate(), JSON serialisation via .model_dump_json(), and schema generation via .model_json_schema().