{"id":17527008,"url":"https://github.com/BoundaryML/baml","last_synced_at":"2025-03-06T06:31:28.365Z","repository":{"id":205907859,"uuid":"701494311","full_name":"BoundaryML/baml","owner":"BoundaryML","description":"BAML is a language that helps you get structured data from LLMs, with the best DX possible. Works with all languages. Check out the promptfiddle.com playground","archived":false,"fork":false,"pushed_at":"2024-10-13T16:57:43.000Z","size":70959,"stargazers_count":1148,"open_issues_count":65,"forks_count":38,"subscribers_count":11,"default_branch":"canary","last_synced_at":"2024-10-13T23:04:33.912Z","etag":null,"topics":["baml","boundaryml","guardrails","llm","llm-playground","playground","prompt","prompt-config","prompt-templates","structured-data","structured-generation","structured-output","vscode"],"latest_commit_sha":null,"homepage":"https://docs.boundaryml.com","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BoundaryML.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-06T18:57:41.000Z","updated_at":"2024-10-13T19:05:00.000Z","dependencies_parsed_at":"2023-12-18T19:04:46.704Z","dependency_job_id":"87782405-cb45-44d3-8ae5-c108d7f8bed9","html_url":"https://github.com/BoundaryML/baml","commit_stats":{"total_commits":1450,"total_committers":23,"mean_commits":63.04347826086956,"dds":0.7648275862068965,"last_synced_commit":"752824723404a4ed4c4b1e31c43d140e9346dca2"},"previous_names":["gloohq/baml","boundaryml/baml"],"tags_count":281,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoundaryML","download_url":"https://codeload.github.com/BoundaryML/baml/tar.gz/refs/heads/canary","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220753131,"owners_count":16697311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["baml","boundaryml","guardrails","llm","llm-playground","playground","prompt","prompt-config","prompt-templates","structured-data","structured-generation","structured-output","vscode"],"created_at":"2024-10-20T15:02:56.238Z","updated_at":"2025-03-06T06:31:28.353Z","avatar_url":"https://github.com/BoundaryML.png","language":"Rust","funding_links":[],"categories":["A01_文本生成_文本对话","Rust","Libraries","vscode","\u003ca name=\"Rust\"\u003e\u003c/a\u003eRust","Uncategorized","📊 Structured Output \u0026 Data Extraction"],"sub_categories":["大语言对话模型及数据","Artificial Intelligence","Uncategorized"],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://boundaryml.com?utm_source=github\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"fern/assets/baml-lamb-white.png\"\u003e\n    \u003cimg src=\"fern/assets/baml-lamb-white.png\" height=\"64\" id=\"top\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n## BAML: Basically a Made-up Language\n\n*or \"Bad-Ass Machine Learning\" if your boss isn't around*\n\n\n\u003ch3\u003e\n\n[Homepage](https://www.boundaryml.com/) | [Docs](https://docs.boundaryml.com) | [BAML Chat](https://www.boundaryml.com/chat) | [Discord](https://discord.gg/BTNBeXGuaS)\n\n\u003c/h3\u003e\n\n[![GitHub Repo stars](https://img.shields.io/github/stars/boundaryml/baml)](https://github.com/boundaryml/baml)\n[![License: Apache-2](https://img.shields.io/badge/License-Apache-green.svg)](https://opensource.org/licenses/Apache-2)\n[![BAML Version](https://img.shields.io/pypi/v/baml-py?color=006dad\u0026label=BAML%20Version)](https://pypi.org/project/baml-py/)\n\n\n**Try BAML**: [Prompt Fiddle](https://www.promptfiddle.com) • [Examples](https://baml-examples.vercel.app/) • [Example Source Code](https://github.com/BoundaryML/baml-examples)\n\n**5 minute quickstarts**\n[Python](https://docs.boundaryml.com/guide/installation-language/python) • [Typescript](https://docs.boundaryml.com/guide/installation-language/typescript) • [NextJS](https://docs.boundaryml.com/guide/framework-integration/react-next-js/quick-start) • [Ruby](https://docs.boundaryml.com/guide/installation-language/ruby) • [Others](https://docs.boundaryml.com/guide/installation-language/rest-api-other-languages) (Go, Java, C++, Rust, PHP, etc)\n\n\u003c/div\u003e\n\n|   |     |\n| - | - |\n| What is BAML? | BAML is a new programming language for builing AI applications. |\n| Do I need to write my whole app in BAML? | Nope, only the AI parts, you can then use BAML with any existing language of your choice! [python](/python), [typescript](/ts), and [more](/more). |\n| Is BAML stable? | Yes, many companies use it in production! We ship updates weekly and rarely have breaking changes |\n| Why a new language? | [Jump to section](#why-a-new-programming-language) |\n| Why a lamb? | Baaaaa-ml. LAMB == BAML |\n\n\n## The core BAML principle: LLM Prompts are functions\n\nThe fundamental building block in BAML is a function. Every prompt is a function that takes in parameters and returns a type.\n\n```baml\nfunction ChatAgent(message: Message[], tone: \"happy\" | \"sad\") -\u003e string\n```\n\nEvery function additionally defines which models it uses and what its prompt is.\n\n```baml\nfunction ChatAgent(message: Message[], tone: \"happy\" | \"sad\") -\u003e StopTool | ReplyTool {\n    client \"openai/gpt-4o-mini\"\n\n    prompt #\"\n        Be a {{ tone }} bot.\n\n        {{ ctx.output_format }}\n\n        {% for m in message %}\n        {{ _.role(m.role) }}\n        {{ m.content }}\n        {% endfor %}\n    \"#\n}\n\nclass Message {\n    role string\n    content string\n}\n\nclass ReplyTool {\n  response string\n}\n\nclass StopTool {\n  action \"stop\" @description(#\"\n    when it might be a good time to end the conversation\n  \"#)\n}\n```\n\nThen in any language of your choice you can do the following:\n\n```python\nfrom baml_client import b\nfrom baml_client.types import Message, StopTool\n\nmessages = [Message(role=\"assistant\", content=\"How can I help?\")]\n\nwhile True:\n  print(messages[-1].content)\n  user_reply = input()\n  messages.append(Message(role=\"user\", content=user_reply))\n  tool = b.ChatAgent(messages, \"happy\")\n  if isinstance(tool, StopTool):\n    print(\"Goodbye!\")\n    break\n  else:\n    messages.append(Message(role=\"assistant\", content=tool.reply))\n```\n\n### Making prompts easy to find and read\n\nSince every prompt is a function, we can build tools to find every prompt you've written. But we've taken BAML one step further and built native tooling for VSCode (jetbrains + neovim coming soon).\n\n1. You can see the full prompt (including any multi-modal assets)\n![Multi Modal](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/02-multi-modal.gif)\n2. You can see the exact network request we are making\n![Token Preview](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/03-curl-token-preview.gif)\n3. You can see every function you've ever written\n\n![Functions](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/04-functions-preview.png)\n\n### Swapping models: 1-line change\n\nIt's just 1 line (ok, maybe 2). [Docs](https://docs.boundaryml.com/guide/baml-basics/switching-llms)\n![Sorry Sam](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/05-sorry-sam.png)\n\n[Retry policies](https://docs.boundaryml.com/ref/llm-client-strategies/retry-policy) • [fallbacks](https://docs.boundaryml.com/ref/llm-client-strategies/fallback) • [model rotations](https://docs.boundaryml.com/ref/llm-client-strategies/round-robin). All statically defined.\n![Fallback Retry](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/06-fallback-retry.gif)\n\n\u003e Want to do pick models at runtime? Check out [Client Registry](https://docs.boundaryml.com/guide/baml-advanced/llm-client-registry).\n\nWe currently support: [OpenAI](https://docs.boundaryml.com/ref/llm-client-providers/open-ai) • [Anthropic](https://docs.boundaryml.com/ref/llm-client-providers/anthropic) • [Gemini](https://docs.boundaryml.com/ref/llm-client-providers/google-ai-gemini) • [Vertex](https://docs.boundaryml.com/ref/llm-client-providers/google-vertex) • [Bedrock](https://docs.boundaryml.com/ref/llm-client-providers/aws-bedrock) • [Azure OpenAI](https://docs.boundaryml.com/ref/llm-client-providers/open-ai-from-azure) • [Anything OpenAI Compatible](https://docs.boundaryml.com/ref/llm-client-providers/openai-generic) ([Ollama](https://docs.boundaryml.com/ref/llm-client-providers/openai-generic-ollama), [OpenRouter](https://docs.boundaryml.com/ref/llm-client-providers/openai-generic-open-router), [VLLM](https://docs.boundaryml.com/ref/llm-client-providers/openai-generic-v-llm), [LMStudio](https://docs.boundaryml.com/ref/llm-client-providers/openai-generic-lm-studio), [TogetherAI](https://docs.boundaryml.com/ref/llm-client-providers/openai-generic-together-ai), and more)\n\n### Hot-reloading for prompts\n\nUsing AI is all about iteration speed.\n\nIf testing your pipeline takes 2 minutes, in 20 minutes, you can only test 10 ideas.\n\nIf testing your pipeline took 5 seconds, in 20 minutes, you can test 240 ideas.\n\nIntroducing testing, for prompts.\n\n![Hot Reload](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/07-hotreload.gif)\n\n### Structured outputs with any LLM\n\nJSON is amazing for REST APIs, but way too strict and verbose for LLMs. LLMs need something flexible. We created the SAP (schema-aligned parsing) algorithm to support the flexible outputs LLMs can provide, like markdown within a JSON blob or chain-of-thought prior to answering.\n\n![Chain of Thought](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/09-cot.gif)\n\nSAP works with any model on day-1, without depending on tool-use or function-calling APIs.\n\nTo learn more about SAP you can read this post: [Schema-Aligned Parsing](https://www.boundaryml.com/blog/schema-aligned-parsing).\n\nSee it in action with: [Deepseek-R1](https://www.boundaryml.com/blog/deepseek-r1-function-calling) and [OpenAI O1](https://www.boundaryml.com/blog/openai-o1).\n\n### Streaming (when it's a first class citizen)\n\nStreaming is way harder than it should be. With our [Python/Typescript/Ruby] generated code, streaming becomes natural and type-safe.\n\n![Streaming](https://www.boundaryml.com/blog/2025-01-24-ai-agents-need-a-new-syntax/10-streaming-client.gif#still)\n\n### No strings attached\n\n- 100% open-source (Apache 2)\n- 100% private. AGI will not require an internet connection, neither will BAML\n    - No network requests beyond model calls you explicitly set\n    - Not stored or used for any training data\n- BAML files can be saved locally on your machine and checked into Github for easy diffs.\n- Built in Rust. So fast, you can't even tell it's there.\n\n## BAML's Design Philosophy\n\nEverything is fair game when making new syntax. If you can code it, it can be yours. This is our design philosophy to help restrict ideas:\n\n- **1:** Avoid invention when possible\n    - Yes, prompts need versioning — we have a great versioning tool: git\n    - Yes, you need to save prompts — we have a great storage tool: filesystems\n- **2:** Any file editor and any terminal should be enough to use it\n- **3:** Be fast\n- **4:** A first year university student should be able to understand it\n\n## Why a new programming language\n\nWe used to write websites like this:\n\n```python\ndef home():\n    return \"\u003cbutton onclick=\\\"() =\u003e alert(\\\\\\\"hello!\\\\\\\")\\\"\u003eClick\u003c/button\u003e\"\n```\n\nAnd now we do this:\n\n```jsx\nfunction Home() {\n  return \u003cbutton onClick={() =\u003e setCount(prev =\u003e prev + 1)}\u003e\n          {count} clicks!\n         \u003c/button\u003e\n}\n```\n\nNew syntax can be incredible at expressing new ideas. Plus the idea of maintaining hundreds of f-strings for prompts kind of disgusts us 🤮. Strings are bad for maintainable codebases. We prefer structured strings.\n\nThe goal of BAML is to give you the expressiveness of English, but the structure of code.\n\nFull [blog post](https://www.boundaryml.com/blog/ai-agents-need-new-syntax) by us.\n\n\n## Conclusion\n\nAs models get better, we'll continue expecting even more out of them. But what will never change is that we'll want a way to write maintainable code that uses those models. The current way we all just assemble strings is very reminiscent of the early days PHP/HTML soup in web development. We hope some of the ideas we shared today can make a tiny dent in helping us all shape the way we all code tomorrow.\n\n\n## Contributing\nCheckout our [guide on getting started](/CONTRIBUTING.md)\n\n---\n\nMade with ❤️ by Boundary\n\nHQ in Seattle, WA\n\nP.S. We're hiring for software engineers that love rust. [Email us](founders@boundaryml.com) or reach out on [discord](https://discord.gg/ENtBB6kkXH)!\n\n\u003cdiv align=\"left\" style=\"align-items: left;\"\u003e\n        \u003ca href=\"#top\"\u003e\n            \u003cimg src=\"https://img.shields.io/badge/Back%20to%20Top-000000?style=for-the-badge\u0026logo=github\u0026logoColor=white\" alt=\"Back to Top\"\u003e\n        \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cimg src=\"https://imgs.xkcd.com/comics/standards.png\" alt_text=\"hi\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBoundaryML%2Fbaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBoundaryML%2Fbaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBoundaryML%2Fbaml/lists"}