applications: Application does not detect output_type changes between calls
Author: harsh4vardhanCreated Aug 6, 2026Updated Aug 11, 2026
Application.__call__ caches the generator and re-creates it only when model changes (line 101):
if model != self.model:
self.model = model
self.generator = Generator(model, self.output_type)output_type is a public instance attribute. If it is mutated between calls with the same model, the stale generator — built for the old type — is silently reused. The new constraint is never applied.
Minimum example:
from outlines.applications import Application
from unittest.mock import MagicMock, patch
with patch("outlines.applications.Generator") as MockGenerator:
calls = []
MockGenerator.side_effect = lambda m, ot: calls.append(ot) or MagicMock()
app = Application(MagicMock(), output_type=int)
model = MagicMock()
app(model, {}) # generator built for int
app.output_type = str
app(model, {}) # same model — generator NOT rebuilt
print(calls) # [<class 'int'>] — str was never usedFix: extend the invalidation condition to also detect output_type changes:
if model != self.model or self.output_type != self._cached_output_type:(or track the output type that was used when the current generator was built).
Source: dottxt-ai/outlines