{"record":{"id":"79189402d1ab0693","repo":"microsoft/semantic-kernel","slug":"radius-and-height-must-be-non-negative","errorCode":null,"errorMessage":"Radius and height must be non-negative.","messagePattern":"Radius and height must be non-negative\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"python/samples/concepts/auto_function_calling/nexus_raven.py","lineNumber":235,"sourceCode":"    def get_prompt_execution_settings_class(self) -> type[PromptExecutionSettings]:\n        return NexusRavenPromptExecutionSettings\n\n\n##########################################################\n# Step 1: Define the functions you want to articulate. ###\n##########################################################\n\n\nclass MathPlugin:\n    @kernel_function\n    def cylinder_volume(\n        self,\n        radius: Annotated[float, \"The radius of the base of the cylinder.\"],\n        height: Annotated[float, \"The height of the cylinder.\"],\n    ):\n        \"\"\"Calculate the volume of a cylinder.\"\"\"\n        if radius < 0 or height < 0:\n            raise ValueError(\"Radius and height must be non-negative.\")\n\n        return math.pi * (radius**2) * height\n\n    @kernel_function\n    def add(\n        self,\n        input: Annotated[float, \"the first number to add\"],\n        amount: Annotated[float, \"the second number to add\"],\n    ) -> Annotated[float, \"the output is a number\"]:\n        \"\"\"Returns the Addition result of the values provided.\"\"\"\n        return MathPlugin.calculator(input, amount, \"add\")\n\n    @kernel_function\n    def subtract(\n        self,\n        input: Annotated[float, \"the first number\"],\n        amount: Annotated[float, \"the number to subtract\"],\n    ) -> float:","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/concepts/auto_function_calling/nexus_raven.py#L217-L253","documentation":"A domain-validation ValueError in the sample MathPlugin.cylinder_volume: it refuses negative radius or height because a cylinder's geometric dimensions are non-negative. It is kernel_function sample logic demonstrating annotated plugin functions, not a library-level error.","triggerScenarios":"Invoking the cylinder_volume kernel function (directly or via the NexusRaven auto-function-calling loop) with radius < 0 or height < 0.","commonSituations":"The model hallucinates a negative value, a caller passes a sign error, or a test feeds -1 to confirm validation. mathematically pi * r^2 * h would still compute for negatives, so this guard exists to enforce the physical constraint.","solutions":["Pass non-negative radius and height.","Take the absolute value before calling if sign is irrelevant to your use case.","Improve the function description / parameter annotations so the model does not emit negatives."],"exampleFix":"# before\nif radius < 0 or height < 0:\n    raise ValueError(\"Radius and height must be non-negative.\")\nreturn math.pi * (radius**2) * height\n# after - normalize and compute\nradius, height = abs(radius), abs(height)\nreturn math.pi * (radius**2) * height","handlingStrategy":"validation","validationCode":"def cylinder_volume(radius: float, height: float) -> float:\n    if radius < 0 or height < 0:\n        raise ValueError(\"Radius and height must be non-negative.\")\n    import math\n    return math.pi * (radius**2) * height\n\n# pre-call guard\ndef safe_cylinder_volume(radius, height):\n    return cylinder_volume(abs(radius), abs(height))","typeGuard":"def is_non_negative(x: object) -> bool:\n    return isinstance(x, (int, float)) and x >= 0","tryCatchPattern":"try:\n    vol = cylinder_volume(r, h)\nexcept ValueError as e:\n    # tell the caller/agent the constraint\n    print(e)","preventionTips":["Validate numeric plugin inputs before invoking.","Document the non-negative constraint in the parameter annotation so the model respects it.","Prefer abs() if sign is irrelevant to your domain."],"tags":["python","sample","validation","math","kernel-function"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}