{"record":{"id":"65358224f299995c","repo":"PrefectHQ/fastmcp","slug":"cannot-specify-both-default-and-default-factory","errorCode":null,"errorMessage":"Cannot specify both 'default' and 'default_factory' in ArgTransform. Use either 'default' for a static value or 'default_factory' for a callable.","messagePattern":"Cannot specify both 'default' and 'default_factory' in ArgTransform\\. Use either 'default' for a static value or 'default_factory' for a callable\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/tools/tool_transform.py","lineNumber":188,"sourceCode":"        ```\n    \"\"\"\n\n    name: str | NotSetT = NotSet\n    description: str | NotSetT = NotSet\n    default: Any | NotSetT = NotSet\n    default_factory: Callable[[], Any] | NotSetT = NotSet\n    type: Any | NotSetT = NotSet\n    hide: bool = False\n    required: Literal[True] | NotSetT = NotSet\n    examples: Any | NotSetT = NotSet\n\n    def __post_init__(self):\n        \"\"\"Validate that only one of default or default_factory is provided.\"\"\"\n        has_default = self.default is not NotSet\n        has_factory = self.default_factory is not NotSet\n\n        if has_default and has_factory:\n            raise ValueError(\n                \"Cannot specify both 'default' and 'default_factory' in ArgTransform. \"\n                \"Use either 'default' for a static value or 'default_factory' for a callable.\"\n            )\n\n        if has_factory and not self.hide:\n            raise ValueError(\n                \"default_factory can only be used with hide=True. \"\n                \"Visible parameters must use static 'default' values since JSON schema \"\n                \"cannot represent dynamic factories.\"\n            )\n\n        if self.required is True and (has_default or has_factory):\n            raise ValueError(\n                \"Cannot specify 'required=True' with 'default' or 'default_factory'. \"\n                \"Required parameters cannot have defaults.\"\n            )\n\n        if self.hide and self.required is True:","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/tools/tool_transform.py#L170-L206","documentation":"ArgTransform validates in __post_init__ that at most one of 'default' (a static value) and 'default_factory' (a callable producing a value) is set. Both encode a default, so specifying both is ambiguous and rejected with ValueError.","triggerScenarios":"Constructing ArgTransform(default=..., default_factory=..., ...) with both fields non-NotSet, e.g. when converting ArgTransformConfig dicts or copy-pasting transform definitions.","commonSituations":"Migrating an existing ArgTransform to use default_factory but forgetting to remove default=; building transforms programmatically and merging two config dicts.","solutions":["Keep only one: remove default= if you need a dynamically computed default (default_factory).","Or remove default_factory= if the default is a static value and keep default=.","If the value came from config, ensure only one of the two keys is present before constructing ArgTransform."],"exampleFix":"// before\nArgTransform(default=5, default_factory=lambda: compute())\n\n// after\nArgTransform(default_factory=lambda: compute())","handlingStrategy":"validation","validationCode":"def check_arg_transform(t: ArgTransform) -> None:\n    if t.default is not NotSet and t.default_factory is not NotSet:\n        raise ValueError(\"Specify only one of default or default_factory\")","typeGuard":null,"tryCatchPattern":"try:\n    t = ArgTransform(default=1, default_factory=int)\nexcept ValueError as e:\n    log.warning(\"Bad ArgTransform: %s\", e)\n    t = ArgTransform(default=1)  # fallback to static default","preventionTips":["Pick default for static values and default_factory for computed ones — never both.","When merging config dicts, filter out one of the two keys first.","Construct ArgTransforms in one place so the rule is easy to enforce."],"tags":["python","tool-transform","validation"],"backgroundTag":"mutually-exclusive-parameters","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}