# load_basemodels_if_needed

## autogen.tools.load_basemodels_if_needed

```
load_basemodels_if_needed(func)
```

A decorator to load the parameters of a function if they are Pydantic models

| PARAMETER | DESCRIPTION |
| --- | --- |
| `func` | The function with annotated parameters<br>**TYPE:**`Callable[..., Any]` |

| RETURNS | DESCRIPTION |
| --- | --- |
| `Callable[..., Any]` | A function that loads the parameters before calling the original function |

Source code in `autogen/tools/function_utils.py`

|     |     |
| --- | --- |
| ```<br>345<br>346<br>347<br>348<br>349<br>350<br>351<br>352<br>353<br>354<br>355<br>356<br>357<br>358<br>359<br>360<br>361<br>362<br>363<br>364<br>365<br>366<br>367<br>368<br>369<br>370<br>371<br>372<br>373<br>374<br>375<br>376<br>377<br>378<br>379<br>380<br>381<br>382<br>383<br>384<br>385<br>386<br>387<br>388<br>``` | ```<br>@export_module("autogen.tools")<br>def load_basemodels_if_needed(func: Callable[..., Any]) -> Callable[..., Any]:<br>    """A decorator to load the parameters of a function if they are Pydantic models<br>    Args:<br>        func: The function with annotated parameters<br>    Returns:<br>        A function that loads the parameters before calling the original function<br>    """<br>    # get the type annotations of the parameters<br>    typed_signature = get_typed_signature(func)<br>    param_annotations = get_param_annotations(typed_signature)<br>    # get functions for loading BaseModels when needed based on the type annotations<br>    kwargs_mapping_with_nones = {k: get_load_param_if_needed_function(t) for k, t in param_annotations.items()}<br>    # remove the None values<br>    kwargs_mapping = {k: f for k, f in kwargs_mapping_with_nones.items() if f is not None}<br>    # a function that loads the parameters before calling the original function<br>    @functools.wraps(func)<br>    def _load_parameters_if_needed(*args: Any, **kwargs: Any) -> Any:<br>        # load the BaseModels if needed<br>        for k, f in kwargs_mapping.items():<br>            kwargs[k] = f(kwargs[k], param_annotations[k])<br>        # call the original function<br>        return func(*args, **kwargs)<br>    @functools.wraps(func)<br>    async def _a_load_parameters_if_needed(*args: Any, **kwargs: Any) -> Any:<br>        # load the BaseModels if needed<br>        for k, f in kwargs_mapping.items():<br>            kwargs[k] = f(kwargs[k], param_annotations[k])<br>        # call the original function<br>        return await func(*args, **kwargs)<br>    if is_coroutine_callable(func):<br>        return _a_load_parameters_if_needed<br>    else:<br>        return _load_parameters_if_needed<br>``` |
