Skip to content

add input validation and error handling to move_one_step tool #54

@apoorvasj

Description

@apoorvasj

I noticed that the move_one_step

def move_one_step(agent: "LLMAgent", direction: str) -> str:
tool currently assumes the direction argument will always be one of the documented values (North, South, East etc.) and directly indexes into direction_map.

This is in contrast to the tools used in the Mesa LLM examples that raise ValueError() for invalid arguments.

Describe the bug

Since this tool is intended to be called by an LLM the input is not guaranteed to match the expected values exactly. The LLM may produce variations such as

  1. Different casing ("north")
  2. Alternate spellings ("north east")
  3. Other invalid directions
    This results in an unhandled KeyError

Current behavior

dx, dy = direction_map[direction]

Can result in KeyError if direction is invalid.

Proposed Fix

Add explicit input validation and raise a clear ValueError when an invalid direction is provided that mentions the valid directions.
If this is accepted, I would also like to update the tests to reflect this change.

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