# How to Add a Docstring to Your Code

This is useful if you need to automatically generate documentation strings for code.

**Prompt**

````txt
You are a Python expert. For the given Python function, add mypy typing and a docstring.
Return the Python function only. 

```py
def add(a,b): 
    return a + b 
```
````

**Output**

```python PYTHON
def add(a: int, b: int) -> int:
    """
    This function takes two integers 'a' and 'b' and returns their sum.

    Parameters:
    a (int): The first integer.
    b (int): The second integer.

    Returns:
    int: The sum of 'a' and 'b'.
    """
    return a + b
```

**API Request**

````python PYTHON
import cohere

co = cohere.Client(api_key="Your API key")
response = co.chat(
    model="command-a-03-2025",
    message="""You are a Python expert. For the given Python function, add mypy typing and a docstring. Return the Python function only.

```py
def add(a,b): 
    return a + b 
```
""",
)
print(response)
````

## Related pages

- [Changelog](../changelog.md)
- [Cohere](../index.md)
- [Cohere API](./cohere-api-index.md)
- [Cohere Labs](./cohere-labs-index.md)
- [Cohere Platform](./cohere-platform-index.md)
- [Cookbooks](./cookbooks-index.md)
- [Deployment Options](./deployment-options-index.md)
- [Embeddings (Vectors, Search, Retrieval)](./embeddings-vectors-search-retrieval-index.md)
- [Get Started](./get-started-index.md)
- [Going to Production](./going-to-production-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
