BAML क्या है?
BAML एक prompting language जो LLM prompts को typed functions में बदलती है और भरोसेमंद structured output देती है. यह App Orchestration टूल्स की Structured Output श्रेणी में आता है; ओपन सोर्स है और Rust में लिखा गया है। शुरू करने के लिए: इंस्टॉल और initialize करें.
सारांश
BAML ("Basically a Made-up Language") LLM prompts लिखने के लिए एक छोटी domain-specific language है। स्ट्रिंग्स को हाथ से जोड़ने के बजाय, आप हर prompt को typed inputs और typed return value वाले function के रूप में परिभाषित करते हैं। इसका Rust compiler एक client library (baml_client) जनरेट करता है, जिसे आप अपने कोड से कॉल करते हैं। इस तरह model का आउटपुट कच्चे text की जगह structured, type-safe data के रूप में आता है, जिसे आपको खुद parse नहीं करना पड़ता।
यह उन developers के लिए है जो AI workflows और agents बना रहे हैं और अलग-अलग models में अनुमानित, structured आउटपुट चाहते हैं। BAML में आप सिर्फ़ prompts लिखते हैं; आपके ऐप का बाकी हिस्सा उसी भाषा में रहता है जिसे आप पहले से इस्तेमाल करते हैं। BAML Python, TypeScript, Ruby और Go के लिए quickstarts देता है, और दूसरी भाषाओं के लिए REST API का रास्ता भी।
Structured-output और LLM orchestration के क्षेत्र में BAML schema engineering पर फ़ोकस करता है। इसमें streaming, retries, fallbacks और model rotations शामिल हैं। इसका schema-aligned parsing (SAP) approach लचीले model responses को संभालता है, भले ही कोई model native tool-calling APIs सपोर्ट न करता हो।
यह क्या करता है
- Typed parameters और return types वाले functions के रूप में prompts परिभाषित करें, जो एक जनरेट हुए baml_client में compile होते हैं
- वही BAML functions Python, TypeScript, Ruby, Go, या REST API के ज़रिए किसी भी भाषा से कॉल करें
- Schema-aligned parsing (SAP) से भरोसेमंद structured output और tool-calling, उन models के साथ भी जिनमें native tool-call APIs नहीं हैं
- Type-safe streaming, जिसमें stream के दौरान आंशिक नतीजे और अंत में एक typed response मिलता है
- Client line बदलकर कई models के बीच स्विच करें, retry policies, fallbacks और round-robin model rotations के साथ
- VS Code और JetBrains के लिए IDE tooling, जिससे prompts को visualize करें, raw API request देखें और playground में tests चलाएं
शुरू करें
अपनी भाषा के लिए BAML package इंस्टॉल करें, एक project initialize करें, .baml फ़ाइल में function लिखें, फिर client जनरेट करके अपने कोड से उसे कॉल करें। नीचे दिया उदाहरण Python का इस्तेमाल करता है।
इंस्टॉल और initialize करें
Python package इंस्टॉल करें और एक BAML project scaffold करें। इससे आपकी .baml फ़ाइलों के लिए baml_src डायरेक्टरी बनती है।
pip install baml-py
baml-cli initBAML में एक function परिभाषित करें
अपनी .baml फ़ाइल में typed inputs और typed return value वाला function घोषित करें, साथ में वह model जो वह इस्तेमाल करता है और उसका prompt।
function ChatAgent(message: Message[], tone: "happy" | "sad") -> StopTool | ReplyTool {
client "openai/gpt-4o-mini"
prompt #"
Be a {{ tone }} bot.
{{ ctx.output_format }}
{% for m in message %}
{{ _.role(m.role) }}
{{ m.content }}
{% endfor %}
"#
}Client जनरेट करें
generate चलाएं ताकि baml_client कोड बने, जिससे आप अपने BAML functions कॉल कर सकें। VS Code extension इंस्टॉल हो तो यह save होने पर अपने-आप भी चल जाता है।
baml-cli generateअपने कोड से इसे कॉल करें
जनरेट हुए client को import करें और अपना function कॉल करें। Return value typed है, इसलिए आप नतीजे के आधार पर branch कर सकते हैं।
from baml_client import b
from baml_client.types import Message, StopTool
messages = [Message(role="assistant", content="How can I help?")]
tool = b.ChatAgent(messages, "happy")
if isinstance(tool, StopTool):
print("Goodbye!")कमांड और कोड प्रोजेक्ट के अपने दस्तावेज़ों से लिए गए हैं — हमेशा जांचें आधिकारिक repo ताज़ा जानकारी के लिए।
कब इस्तेमाल करें
- Resume या दस्तावेज़ से fields जैसे structured data को खुद JSON parse करने के बजाय typed objects में निकालना
- Chat agents और multi-step workflows को while loops के रूप में बनाना, जो shared state के साथ chained BAML functions कॉल करते हैं
- ऐसे models से भरोसेमंद tool-calling और structured output पाना जो native tool-call APIs सपोर्ट नहीं करते
- अपने application code को बदले बिना कई providers में retries, fallbacks और model rotations जोड़ना
How BAML compares
BAML alongside other open-source structured output tools AI/TLDR tracks, ranked by GitHub stars.
| टूल | स्टार | यह क्या करता है |
|---|---|---|
| Laya | ★ 36.1k | टेक्स्ट के बारे में टाइप किए गए सवाल पूछें और कैलिब्रेटेड संभावनाएँ पाएँ, जनरेट किया हुआ JSON नहीं |
| Guidance | ★ 21.8k | Constrained, structured generation के साथ LLM को नियंत्रित करने वाला एक programming model |
| Outlines | ★ 16k | किसी भी LLM को हमेशा valid structured output देने के लिए बाध्य करें |
| Instructor | ★ 14.2k | किसी भी LLM से भरोसेमंद structured आउटपुट, Pydantic से validated |
| BAML | ★ 9.6k | एक prompting language जो LLM prompts को typed functions में बदलती है और भरोसेमंद structured output देती है |
| Marvin | ★ 6.2k | LLM calls को typed Python functions और agentic workflows में बदलें |
| SemIf | ★ 5k | किसी ओपन मॉडल से JSON जनरेट कराने के बजाय, टाइप किए गए विकल्पों की संभावनाएँ सीधे पढ़ें |
| LM Format Enforcer | ★ 2k | tokens फ़िल्टर करके LLM का आउटपुट JSON Schema या regex के अनुरूप बाध्य करें |

