Skip to content

convert_function_to_tool: undocumented parameter named args gets the whole Args section as its description #765

Open

Description

@RaphaelFakhri

When a function passed as a tool has a parameter named args that the docstring does not document, the generated tool schema uses the raw text of the docstring's Args: section as that parameter's description.

_parse_docstring stores the raw section under the args key of the same dictionary that convert_function_to_tool uses to look up descriptions by parameter name.

Steps to reproduce

from ollama._utils import convert_function_to_tool

def run_command(command: str, args: list) -> str:
  """
  Run a shell command.

  Args:
    command: The executable to run
  """

tool = convert_function_to_tool(run_command)
print(repr(tool.function.parameters.properties['args'].description))

Expected behavior

'', as for any other undocumented parameter.

Actual behavior

'command: The executable to run\n\n'. The model sees another parameter's documentation as the description of args.

The same collision gives a parameter named _ the text of the Returns: section.

Environment

ollama-python main (35d9667), Python 3.9, pydantic 2.13.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions