# PythonTools returns a variable that holds None

> Agno's PythonTools now returns 'None' for a variable_to_return whose value is None, and keeps 'Variable <name> not found' for a name the code never defined.

- Published: 2026-10-01
- Author: 澍
- Categories: Changelog
- Canonical: https://www.agno.com/blog/pythontools-returns-a-variable-that-holds-none
- Markdown: https://www.agno.com/blog/pythontools-returns-a-variable-that-holds-none.md

Agno's `PythonTools.run_python_code`, `save_to_file_and_run` and `run_python_file_return_variable` now check that `variable_to_return` exists in the namespace before they read it. They used `.get()` and treated a `None` result as a missing name, so an agent whose code assigned `None`, like a search that found no match, was told the variable it had just set didn't exist. A defined value still comes back as a string:

```python
from agno.tools.python import PythonTools

PythonTools().run_python_code("match = None", variable_to_return="match")
# Before: 'Variable match not found'
# Now:    'None'

PythonTools().run_python_code("x = 1", variable_to_return="match")
# Before and now: 'Variable match not found'
```

See the [cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/91_tools/python_tools.py), and learn more about [PythonTools](https://docs.agno.com/tools/toolkits/local/python) in the documentation.
