# openai.BadRequestError: Invalid parameter: value for parameter 'temperature' is not a valid number: 'hot'

- **ID:** `llm/function-call-argument-type-mismatch`
- **Domain:** llm
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

LLM generated a function call argument with the wrong data type (e.g., string instead of number) due to ambiguous schema definitions or insufficient prompting for parameter types.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| openai==1.30.0 | active | — | — |
| python==3.11 | active | — | — |

## Workarounds

1. **Add explicit type descriptions in the function schema's parameter descriptions: `'temperature': {'type': 'number', 'description': 'A float between 0 and 2, e.g., 0.7. Do NOT use words like hot or cold.'}` and use `enum` constraints if applicable: `'temperature': {'type': 'number', 'enum': [0.0, 0.5, 1.0, 1.5, 2.0]}`** (85% success)
   ```
   Add explicit type descriptions in the function schema's parameter descriptions: `'temperature': {'type': 'number', 'description': 'A float between 0 and 2, e.g., 0.7. Do NOT use words like hot or cold.'}` and use `enum` constraints if applicable: `'temperature': {'type': 'number', 'enum': [0.0, 0.5, 1.0, 1.5, 2.0]}`
   ```
2. **Implement a validation layer that catches type errors and retries the function call with a corrected prompt: `try: response = client.chat.completions.create(...); except BadRequestError as e: if 'not a valid number' in str(e): corrected_messages = messages + [{'role': 'assistant', 'content': None, 'function_call': ...}, {'role': 'function', 'name': 'validation_error', 'content': f'Type error: {e}'}]; response = retry(corrected_messages)`** (90% success)
   ```
   Implement a validation layer that catches type errors and retries the function call with a corrected prompt: `try: response = client.chat.completions.create(...); except BadRequestError as e: if 'not a valid number' in str(e): corrected_messages = messages + [{'role': 'assistant', 'content': None, 'function_call': ...}, {'role': 'function', 'name': 'validation_error', 'content': f'Type error: {e}'}]; response = retry(corrected_messages)`
   ```

## Dead Ends

- **** — LLMs are not reliably type-safe; they may ignore instructions if the schema is ambiguous or if the model's token distribution favors string outputs. (65% fail)
- **** — This is brittle and doesn't scale; the LLM may generate other invalid types (e.g., arrays instead of objects) that the regex cannot handle. (85% fail)
- **** — This defeats the purpose of structured tool use and introduces more parsing errors from free-form text. (90% fail)
