Skip to main content

Documentation 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.

BasicReturn is the base return model in BasicReturns. It is a Pydantic BaseModel subclass with two fields — ok and error — that signal whether an operation succeeded and, if not, what went wrong.
from BasicReturns import BasicReturn

Class Signature

from typing import Any, Optional
from pydantic import BaseModel

class BasicReturn(BaseModel):
    ok: Optional[bool] = True
    error: Optional[Any] = None

Fields

ok
Optional[bool]
default:"True"
True when the operation completed successfully. Set this to False on failure to signal that something went wrong.
error
Optional[Any]
default:"None"
The exception or error object captured when ok is False. Defaults to None on a successful return.

Methods

to_dict()

Returns a dictionary representation of the instance.
def to_dict(self) -> dict:
    return {"ok": self.ok, "error": self.error}
Return value
ok
bool
Whether the operation succeeded.
error
Any or None
The error if ok is False, otherwise None.

__str__()

Returns a human-readable string representation of the instance, formatted as:
OK: {ok}
Error: {error}

Usage Example

from BasicReturns import BasicReturn

def parse_age(value: str) -> BasicReturn:
    result = BasicReturn()

    try:
        age = int(value)
        if age < 0:
            raise ValueError("Age cannot be negative")
    except Exception as e:
        result.ok = False
        result.error = e

    return result

# Call site
response = parse_age("abc")

if response.ok:
    print("Parsed successfully")
else:
    print(f"Failed: {response.error}")
# Failed: invalid literal for int() with base 10: 'abc'

to_dict() Examples

Success state
result = BasicReturn()
print(result.to_dict())
# {'ok': True, 'error': None}
Failure state
result = BasicReturn()
result.ok = False
result.error = RuntimeError("Something went wrong")
print(result.to_dict())
# {'ok': False, 'error': RuntimeError('Something went wrong')}
BasicReturn is intentionally minimal — it only carries a success flag and an optional error. Use DataAndMsgReturn when you need to return a result payload or a human-readable message alongside the success state.
See DataAndMsgReturn for the extended class.

Build docs developers (and LLMs) love