{"record":{"id":"0c1737d231728189","repo":"PrefectHQ/fastmcp","slug":"default-factory-can-only-be-used-with-hide-true-v","errorCode":null,"errorMessage":"default_factory can only be used with hide=True. Visible parameters must use static 'default' values since JSON schema cannot represent dynamic factories.","messagePattern":"default_factory can only be used with hide=True\\. Visible parameters must use static 'default' values since JSON schema cannot represent dynamic factories\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/tools/tool_transform.py","lineNumber":194,"sourceCode":"    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:\n            raise ValueError(\n                \"Cannot specify both 'hide=True' and 'required=True'. \"\n                \"Hidden parameters cannot be required since clients cannot provide them.\"\n            )\n\n        if self.required is False:","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/tools/tool_transform.py#L176-L212","documentation":"ArgTransform requires default_factory to be paired with hide=True. A visible parameter would need its default expressed in the JSON schema sent to clients, but a callable default cannot be serialized to a schema, so the library rejects the combination with ValueError.","triggerScenarios":"ArgTransform(default_factory=some_callable) without hide=True (hide defaults to False).","commonSituations":"Wanting a per-call generated default (timestamp, uuid, token) while still exposing the parameter in the transformed schema; misunderstanding that factories only work for hidden params.","solutions":["Add hide=True if the parameter should not appear in the transformed schema.","Replace default_factory with a static default= if the parameter must remain visible.","Have the replacement function compute the value itself (via forward_raw / parent call) and drop default_factory."],"exampleFix":"// before\nArgTransform(name=\"api_key\", default_factory=lambda: make_key())\n\n// after\nArgTransform(name=\"api_key\", default_factory=lambda: make_key(), hide=True)","handlingStrategy":"validation","validationCode":"def check_factory_hidden(t: ArgTransform) -> None:\n    if t.default_factory is not NotSet and not t.hide:\n        raise ValueError(\"default_factory requires hide=True\")","typeGuard":null,"tryCatchPattern":"try:\n    t = ArgTransform(default_factory=make)\nexcept ValueError:\n    t = ArgTransform(default_factory=make, hide=True)","preventionTips":["Remember: dynamic defaults are invisible to JSON schema — they only work on hidden params.","If the param must be visible, compute its value inside the replacement function instead.","Review ArgTransform definitions for default_factory without hide during code review."],"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"}