ruvnet/ruflo · error

Temperature must be between 0 and 2

Error message

Temperature must be between 0 and 2

What it means

validateConfig() enforces the documented sampling-temperature range: when config.temperature is provided it must be a number in [0, 2] inclusive; anything outside throws during provider initialization, before any API request is made.

Source

Thrown at v3/@claude-flow/providers/src/base-provider.ts:203

   * Provider-specific initialization (override in subclass)
   */
  protected abstract doInitialize(): Promise<void>;

  /**
   * Validate provider configuration
   */
  protected validateConfig(): void {
    if (!this.config.model) {
      throw new Error(`Model is required for ${this.name} provider`);
    }

    if (!this.validateModel(this.config.model)) {
      this.logger.warn(`Model ${this.config.model} may not be supported by ${this.name}`);
    }

    if (this.config.temperature !== undefined) {
      if (this.config.temperature < 0 || this.config.temperature > 2) {
        throw new Error('Temperature must be between 0 and 2');
      }
    }
  }

  /**
   * Complete a request
   */
  async complete(request: LLMRequest): Promise<LLMResponse> {
    const startTime = Date.now();

    try {
      const response = await this.circuitBreaker.execute(async () => {
        return await this.doComplete(request);
      });

      const latency = Date.now() - startTime;
      this.trackRequest(request, response, latency);

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Set temperature within 0-2 (0.7 is a common default)
  2. Clamp external input before passing it: Math.min(2, Math.max(0, t))
  3. Omit temperature entirely to use the provider default

Example fix

// before
config: { apiKey, model: 'gpt-4o', temperature: 7 } // copied from a 0-10 scale

// after
config: { apiKey, model: 'gpt-4o', temperature: Math.min(2, Math.max(0, 0.7)) }
Defensive patterns

Strategy: validation

Validate before calling

function clampTemperature(t: number | undefined): number | undefined {
  if (t === undefined) return undefined;
  if (!Number.isFinite(t)) throw new Error('temperature must be a finite number');
  return Math.min(2, Math.max(0, t));
}
// usage: config: { ...cfg, temperature: clampTemperature(cfg.temperature) }

Type guard

function isValidTemperature(t: unknown): t is number {
  return typeof t === 'number' && Number.isFinite(t) && t >= 0 && t <= 2;
}

Prevention

When it happens

Trigger: Initializing a provider with temperature: -0.5 or temperature: 3, or a value scaled from another tool's 0-10 range, or a temperature computed from a string env var that ends up out of bounds.

Common situations: Hyperparameters copy-pasted from a library using a 0-1 or 0-10 scale; a UI slider permitting values above 2; env var parsed with parseFloat producing an unexpected value.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/613845063a6ad81f. Report an issue: GitHub.