Skip to content

FixedArgsTestModel

Base classes

Name Children Inherits
TestModel
pydantic_ai.models.test
A model specifically for testing purposes.

â‹” Inheritance diagram

graph TD
  3973672691["test_model.FixedArgsTestModel"]
  328545894["test.TestModel"]
  3233824472["_in_memory_batch.InMemoryBatchModel"]
  956387754["models.Model"]
  1457841118["_abstract.AbstractModel"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  3481597255["typing.Generic"]
  328545894 --> 3973672691
  3233824472 --> 328545894
  956387754 --> 3233824472
  1457841118 --> 956387754
  925645236 --> 1457841118
  2751680898 --> 925645236
  3481597255 --> 956387754
  2751680898 --> 3481597255

🛈 DocStrings

Bases: TestModel

TestModel subclass that supports fixed tool arguments.

This is useful for testing scenarios where you need deterministic, specific tool arguments instead of auto-generated ones.

Example
model = FixedArgsTestModel(
    call_tools=['read_file'],
    tool_args={'read_file': {'path': '/test/hello.txt'}}
)
# When read_file is called, it will use {'path': '/test/hello.txt'}
# instead of generating random args from the schema
Source code in src/llmling_models/models/test_model.py
@dataclass(init=False)
class FixedArgsTestModel(TestModel):
    """TestModel subclass that supports fixed tool arguments.

    This is useful for testing scenarios where you need deterministic,
    specific tool arguments instead of auto-generated ones.

    Example:
        ```python
        model = FixedArgsTestModel(
            call_tools=['read_file'],
            tool_args={'read_file': {'path': '/test/hello.txt'}}
        )
        # When read_file is called, it will use {'path': '/test/hello.txt'}
        # instead of generating random args from the schema
        ```
    """

    tool_args: dict[str, dict[str, Any]] = field(default_factory=dict)
    """Mapping of tool_name -> args to use instead of generated args."""

    def __init__(
        self,
        *,
        tool_args: dict[str, dict[str, Any]] | None = None,
        call_tools: list[str] | Literal["all"] = "all",
        custom_output_text: str | None = None,
        custom_output_args: Any | None = None,
        seed: int = 0,
    ) -> None:
        """Initialize FixedArgsTestModel.

        Args:
            tool_args: Mapping of tool_name -> args to use for that tool.
                      Tools not in this mapping will use auto-generated args.
            call_tools: List of tools to call, or 'all' to call all tools.
            custom_output_text: Custom text to return as final output.
            custom_output_args: Custom args to pass to output tool.
            seed: Seed for generating random args (for tools not in tool_args).
        """
        super().__init__(
            call_tools=call_tools,
            custom_output_text=custom_output_text,
            custom_output_args=custom_output_args,
            seed=seed,
        )
        self.tool_args = tool_args or {}

    def gen_tool_args(self, tool_def: ToolDefinition) -> Any:
        """Generate tool arguments, using fixed args if available.

        Args:
            tool_def: The tool definition to generate args for.

        Returns:
            Fixed args if tool_name is in tool_args, otherwise auto-generated.
        """
        if tool_def.name in self.tool_args:
            return self.tool_args[tool_def.name]
        return super().gen_tool_args(tool_def)

tool_args class-attribute instance-attribute

tool_args: dict[str, dict[str, Any]] = tool_args or {}

Mapping of tool_name -> args to use instead of generated args.

__init__

__init__(
    *,
    tool_args: dict[str, dict[str, Any]] | None = None,
    call_tools: list[str] | Literal["all"] = "all",
    custom_output_text: str | None = None,
    custom_output_args: Any | None = None,
    seed: int = 0,
) -> None

Initialize FixedArgsTestModel.

Parameters:

Name Type Description Default
tool_args dict[str, dict[str, Any]] | None

Mapping of tool_name -> args to use for that tool. Tools not in this mapping will use auto-generated args.

None
call_tools list[str] | Literal['all']

List of tools to call, or 'all' to call all tools.

'all'
custom_output_text str | None

Custom text to return as final output.

None
custom_output_args Any | None

Custom args to pass to output tool.

None
seed int

Seed for generating random args (for tools not in tool_args).

0
Source code in src/llmling_models/models/test_model.py
def __init__(
    self,
    *,
    tool_args: dict[str, dict[str, Any]] | None = None,
    call_tools: list[str] | Literal["all"] = "all",
    custom_output_text: str | None = None,
    custom_output_args: Any | None = None,
    seed: int = 0,
) -> None:
    """Initialize FixedArgsTestModel.

    Args:
        tool_args: Mapping of tool_name -> args to use for that tool.
                  Tools not in this mapping will use auto-generated args.
        call_tools: List of tools to call, or 'all' to call all tools.
        custom_output_text: Custom text to return as final output.
        custom_output_args: Custom args to pass to output tool.
        seed: Seed for generating random args (for tools not in tool_args).
    """
    super().__init__(
        call_tools=call_tools,
        custom_output_text=custom_output_text,
        custom_output_args=custom_output_args,
        seed=seed,
    )
    self.tool_args = tool_args or {}

gen_tool_args

gen_tool_args(tool_def: ToolDefinition) -> Any

Generate tool arguments, using fixed args if available.

Parameters:

Name Type Description Default
tool_def ToolDefinition

The tool definition to generate args for.

required

Returns:

Type Description
Any

Fixed args if tool_name is in tool_args, otherwise auto-generated.

Source code in src/llmling_models/models/test_model.py
def gen_tool_args(self, tool_def: ToolDefinition) -> Any:
    """Generate tool arguments, using fixed args if available.

    Args:
        tool_def: The tool definition to generate args for.

    Returns:
        Fixed args if tool_name is in tool_args, otherwise auto-generated.
    """
    if tool_def.name in self.tool_args:
        return self.tool_args[tool_def.name]
    return super().gen_tool_args(tool_def)

:fa-brands-github: Show source on GitHub