# BAML — Schema-First Prompting for Agents > BAML treats prompts as typed functions for reliable outputs. Install `baml-py`, define `.baml` functions, then call generated clients from Python. ## Install Save as a script file and run: # BAML — Schema-First Prompting for Agents > BAML treats prompts as typed functions for reliable outputs. Install `baml-py`, define `.baml` functions, then call generated clients from Python. ## Quick Use 1. Install: ```bash pip install baml-py ``` 2. Run: ```bash python -c "import baml_py; print('baml-py installed')" ``` 3. Verify: - Open the repo README and confirm you can define a BAML function and call generated `baml_client` from Python --- ## Intro BAML treats prompts as typed functions for reliable outputs. Install `baml-py`, define `.baml` functions, then call generated clients from Python. - **Best for:** teams iterating on prompts daily who want typesafety, streaming, and retry-friendly workflows without rewriting the whole app - **Works with:** BAML `.baml` files, Python via `baml-py`, and multi-language clients (per repo) - **Setup time:** 15 minutes ### Quantitative Notes - PyPI package: `baml-py` (verified via pip index) - Setup time ~15 minutes - GitHub stars (verified): see Source & Thanks --- ## Practical Notes Adopt BAML when your bottleneck is *iteration speed* and *output stability*. Model your prompt as a function: inputs are typed, outputs are typed, and the prompt body is versionable. Keep a small library of BAML functions (extract, classify, route, summarize) and test them in your IDE before wiring them into agents. Over time, you get a maintainable prompt surface instead of a pile of ad-hoc strings. **Safety note:** Keep function signatures small; overly generic types and huge prompts slow iteration and reduce reliability. ### FAQ **Q: Do I need to write my whole app in BAML?** A: No. The repo emphasizes using BAML for prompts/functions and wiring it into your existing app. **Q: What makes it different from plain prompting?** A: You define a function signature with types and let the tool enforce output structure, retries, and streaming-friendly interfaces. **Q: Is it Python-only?** A: No. The repo lists Python, TypeScript, Ruby, Go, and more client options via generated clients or REST patterns. --- ## Source & Thanks > GitHub: https://github.com/BoundaryML/baml > Owner avatar: https://avatars.githubusercontent.com/u/124114301?v=4 > License (SPDX): Apache-2.0 > GitHub stars (verified via `api.github.com/repos/BoundaryML/baml`): 8,206 --- # BAML——以 Schema 为中心的 Prompt 工程 > BAML 把 prompt 当作「带类型的函数」来写,提升输出稳定性(即使模型不支持 tool-calling)。安装 `baml-py`,定义 `.baml` 函数,再从 Python 调用。 ## 快速使用 1. 安装: ```bash pip install baml-py ``` 2. 运行: ```bash python -c "import baml_py; print('baml-py installed')" ``` 3. 验证: - Open the repo README and confirm you can define a BAML function and call generated `baml_client` from Python --- ## 简介 BAML 把 prompt 当作「带类型的函数」来写,提升输出稳定性(即使模型不支持 tool-calling)。安装 `baml-py`,定义 `.baml` 函数,再从 Python 调用。 - **适合谁(Best for):** 每天迭代 prompt 的团队,希望引入类型安全、流式与可重试工作流,但不想重写整个应用 - **兼容工具(Works with):** BAML `.baml` 文件、Python 的 `baml-py`,以及多语言 client(仓库说明) - **安装时间(Setup time):** 15 分钟 ### 量化信息 - PyPI 包:`baml-py`(已用 pip index 核验) - 装机约 15 分钟 - GitHub stars(已核验):见「来源与感谢」 --- ## 实战要点 当你的瓶颈是「迭代速度」与「输出稳定性」时,BAML 很适合:把 prompt 建模成函数,输入/输出都有类型,prompt 本身可版本化。把常用能力沉淀成一组 BAML 函数(抽取/分类/路由/总结),先在 IDE 里快速测试,再接入 agent。长期看,你会得到可维护的 prompt 工程面,而不是一堆零散字符串。 **安全提示:** 函数签名要小而清晰:类型过于泛化、prompt 过大,会拖慢迭代并降低稳定性。 ### FAQ **Q: 必须用 BAML 重写整个应用吗?** A: 不需要。仓库强调只把 BAML 用在 prompt/function 层,再接入你现有的业务代码。 **Q: 和普通 prompt 有什么不同?** A: 你先定义函数签名与类型,让工具帮助你把输出结构、重试与流式接口工程化,而不是靠临时提示词凑结果。 **Q: 只能 Python 吗?** A: 不是。仓库提到 Python、TypeScript、Ruby、Go 等多语言调用方式(生成 client 或 REST)。 --- ## 来源与感谢 > GitHub:https://github.com/BoundaryML/baml > Owner avatar:https://avatars.githubusercontent.com/u/124114301?v=4 > 许可证(SPDX):Apache-2.0 > GitHub stars(已通过 `api.github.com/repos/BoundaryML/baml` 核验):8,206 --- Source: https://tokrepo.com/en/workflows/baml-schema-first-prompting-for-agents Author: Agent Toolkit