#1997·outlines

mlxlm.generate_batch uses falsy guard (if output_type:) instead of identity check (if output_type is not None:)

Author: harsh4vardhanCreated Aug 13, 2026Updated Aug 13, 2026

Bug Description

MLXLMModel.generate_batch uses a falsy check if output_type: to guard against unsupported structured generation. This is inconsistent with every other method in the codebase, which uses if output_type is not None:. As a result, any truthy-but-falsy output type object (e.g. a logits processor whose __bool__ returns False, or a future output type that overrides __bool__) silently bypasses the guard and proceeds to call batch_generate without the constraint — producing unconstrained output instead of raising NotImplementedError.

Affected file

src/outlines/models/mlxlm.py, line 201:

python
def generate_batch(self, model_input, output_type=None, **kwargs):
    from mlx_lm import batch_generate
    if output_type:                   # BUG: should be `if output_type is not None:`
        raise NotImplementedError(
            "Batch generation with output type is not supported for MLX LM models."
        )
    ...

Minimal reproducer

python
class FalsyOutputType:
    def __bool__(self): return False

output_type = FalsyOutputType()

# The guard as written:
if output_type:
    raise NotImplementedError("Caught")
else:
    print("Guard bypassed — batch_generate runs without constraint")
    # => "Guard bypassed"

# The correct guard used elsewhere:
if output_type is not None:
    raise NotImplementedError("Caught")
    # => NotImplementedError raised correctly

Contrast with other methods

All other generate_* methods in the same file use if output_type is not None: — this is the only outlier.

Fix

Change line 201 from:

python
if output_type:

to:

python
if output_type is not None:

Environment

Reproduced on Python 3.12 with Outlines main branch (2026-08-13).