TurboGears provides a simple means to use FormEncode validators to check whether incoming method arguments are valid and to convert them from strings to appropriate Python types. Here's a simple example:
The validators dictionary passed to turbogears.expose is saying to run the value argument through the Int validator. If it doesn't pass validation, tg_errors will be set. If tg_errors is None, you are assured that value will be an int.
If there is a validation error, tg_errors will be a dictionary. If you look up tg_errors["value"], you'll find an "Invalid" exception object. Invalid exception objects can provide a user-friendly error message. These objects and the original arguments allow you to repopulate an entry form that failed validation.
TurboGears has very powerful and flexible error handling, allowing you to route errors to different methods so that you main controller methods can always work with the knowledge that they are receiving good input. TODO: link to another doc or expand further here.
All of the validators are imported into the turbogears.validators module. You can see the validators that are available by looking at the FormEncode validators module and the TurboGears validators module (TODO: need links).
You can do more advanced validation using a FormEncode validation schema. The validators parameter to expose allows you to pass either a schema or a dictionary as in the example above. For more information about schemas, refer to the FormEncode Validator documentation.