fern/01-guide/09-comparisons/marvin.mdx
Marvin lets developers do extraction or classification tasks in Python as shown below (TypeScript is not supported):
import pydantic
class Location(pydantic.BaseModel):
city: str
state: str
marvin.extract("I moved from NY to CHI", target=Location)
You can also provide instructions:
marvin.extract(
"I paid $10 for 3 tacos and got a dollar and 25 cents back.",
target=float,
instructions="Only extract money"
)
# [10.0, 1.25]
or using enums to classify
from enum import Enum
import marvin
class RequestType(Enum):
SUPPORT = "support request"
ACCOUNT = "account issue"
INQUIRY = "general inquiry"
request = marvin.classify("Reset my password", RequestType)
assert request == RequestType.ACCOUNT
For enum classification, you can add more instructions to each enum, but then you don't get fully typed outputs, nor can reuse the enum in your own code. You're back to working with raw strings.
# Classifying a task based on project specifications
project_specs = {
"Frontend": "Tasks involving UI design, CSS, and JavaScript.",
"Backend": "Tasks related to server, database, and application logic.",
"DevOps": "Tasks involving deployment, CI/CD, and server maintenance."
}
task_description = "Set up the server for the new application."
task_category = marvin.classify(
task_description,
labels=list(project_specs.keys()),
instructions="Match the task to the project category based on the provided specifications."
)
assert task_category == "Backend"
Marvin has some inherent limitations for example:
Here is the BAML equivalent of this classification task based off the prompt Marvin uses under-the-hood. Note how the prompt becomes transparent to you using BAML. You can easily make it more complex or simpler depending on the model.
enum RequestType {
SUPPORT @alias("support request")
ACCOUNT @alias("account issue") @description("A detailed description")
INQUIRY @alias("general inquiry")
}
function ClassifyRequest(input: string) -> RequestType {
client GPT4 // choose even open source models
prompt #"
You are an expert classifier that always maintains as much semantic meaning
as possible when labeling text. Classify the provided data,
text, or information as one of the provided labels:
TEXT:
---
{{ input }}
---
{{ ctx.output_format }}
The best label for the text is:
"#
}
And you can call this function in your code
from baml_client import baml as b
...
requestType = await b.ClassifyRequest("Reset my password")
# fully typed output
assert requestType == RequestType.ACCOUNT
Marvin was a big source of inspiration for us -- their approach is simple and elegant for quick Python prototypes.
BAML's advantages over Marvin:
What this means for your applications:
Marvin is great for: Quick Python prototypes, simple one-off tasks BAML is great for: Production applications, multi-language teams, complex workflows
We recommend checking out Marvin if you're just starting with prompt engineering or need a quick Python solution. But if you're building production applications that need reliability, observability, and multi-language support, try BAML.
BAML does have some limitations we are continuously working on. Here are a few of them: