← all repositories
google/langfun

Prompting LLMs with Python types instead of strings

Langfun exists to make LLM calls feel like native Python function calls, letting you prompt with objects and types instead of raw strings.

913 stars Python Language ModelsML Frameworks
langfun
Not currently ranked — collecting fresh signals.
star history

What it does

Langfun is a PyGlove-powered Python library that reframes LLM interactions as strongly-typed function invocations. You define the desired return shape as a Python class and pass a natural-language prompt to lf.query; the model responds with a populated object rather than a wall of text. It wraps Gemini, GPT, Claude, and Llama3 under a single API without requiring fine-tuning.

The interesting bit

The central pitch is “Object-Oriented Prompting”: you prompt with objects and types instead of wrestling with string interpolation and regex extraction. It is essentially opinionated glue between LLM backends and PyGlove’s symbolic object system, but that glue removes the usual parse-and-pray step from agent development.

Key highlights

  • Prompts are templates that natively accept Python objects and multimodal inputs like images.
  • Supports both one-off requests and batch jobs without changing the programming model.
  • Includes an eval framework that the authors claim thrives on “dimension explosions.”
  • Pitched as drop-in compatible with existing Python codebases, offering intellisense and minimal overhead.
  • Works with major commercial and open models out of the box.

Caveats

  • The project is explicitly not an officially supported Google product.
  • The README is vague on how structured output conformance is actually enforced—whether via constrained decoding, retries, or prompt engineering alone is unstated.
  • The object-oriented model is tightly coupled to PyGlove, so your mileage will vary if you are not already comfortable with symbolic object programming.

Verdict

A pragmatic choice for Python developers who want type-safe, structured LLM outputs and already tolerate PyGlove’s object model. Look elsewhere if you need a fully supported Google product or transparent guarantees about how the LLM is forced to obey your schema.

Frequently asked

What is google/langfun?
Langfun exists to make LLM calls feel like native Python function calls, letting you prompt with objects and types instead of raw strings.
Is langfun open source?
Yes — google/langfun is open source, released under the Apache-2.0 license.
What language is langfun written in?
google/langfun is primarily written in Python.
How popular is langfun?
google/langfun has 913 stars on GitHub.
Where can I find langfun?
google/langfun is on GitHub at https://github.com/google/langfun.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.