Skip to content

FormTarget

Base classes

Name Children Inherits
Generic
typing
Abstract base class for generic types.

⋔ Inheritance diagram

graph TD
  3477954597["target.FormTarget"]
  3481597255["typing.Generic"]
  2751680898["builtins.object"]
  3481597255 --> 3477954597
  2751680898 --> 3481597255

🛈 DocStrings

The schema a form is built from, and how its result is validated.

Source code in src/promptantic/form/target.py
@dataclass(frozen=True)
class FormTarget[T]:
    """The schema a form is built from, and how its result is validated."""

    schema: Mapping[str, Any]
    validate_value: Callable[[Any], T]

    @property
    def title(self) -> str | None:
        return self.schema.get("title")

    def validate(self, value: Any) -> T:
        """The validated result (a model instance for Python types).

        Raises:
            FormValidationError: With every issue found, not only the first.
        """
        return self.validate_value(value)

validate

validate(value: Any) -> T

The validated result (a model instance for Python types).

Raises:

Type Description
FormValidationError

With every issue found, not only the first.

Source code in src/promptantic/form/target.py
def validate(self, value: Any) -> T:
    """The validated result (a model instance for Python types).

    Raises:
        FormValidationError: With every issue found, not only the first.
    """
    return self.validate_value(value)

:fa-brands-github: Show source on GitHub