{"id":4849,"library":"weave","title":"Weave (Weights & Biases)","description":"Weave by Weights & Biases is a Python toolkit designed for developing, observing, and evaluating Generative AI applications. It enables users to log and debug inputs, outputs, and traces of language models, build rigorous evaluations, and organize information across the LLM workflow, from experimentation to production. The library is currently at version 0.52.36 and has an active release cadence.","status":"active","version":"0.52.36","language":"en","source_language":"en","source_url":"https://github.com/wandb/weave","tags":["AI","LLM","observability","tracing","evaluation","Weights & Biases","Generative AI"],"install":[{"cmd":"pip install weave","lang":"bash","label":"Install Weave"}],"dependencies":[{"reason":"Requires Python 3.10 or higher.","package":"python","optional":false},{"reason":"Weave is built by Weights & Biases and integrates with W&B for project management, logging, and visualization. An account is required for full functionality.","package":"wandb","optional":false}],"imports":[{"symbol":"weave","correct":"import weave"},{"note":"The `op` decorator is typically imported directly or accessed as `weave.op` after a general `import weave`.","wrong":"import weave.op","symbol":"op","correct":"from weave import op"}],"quickstart":{"code":"import os\nimport weave\nfrom openai import OpenAI\n\n# Ensure you have your Weights & Biases API key set as an environment variable\n# os.environ['WANDB_API_KEY'] = 'YOUR_WANDB_API_KEY'\n# Ensure you have your OpenAI API key set as an environment variable\n# os.environ['OPENAI_API_KEY'] = 'YOUR_OPENAI_API_KEY'\n\n# Initialize Weave with your project name\n# This will create a new project or connect to an existing one in W&B\nweave.init(project_name=os.environ.get('WANDB_PROJECT_NAME', 'my-llm-project'))\n\nclient = OpenAI()\n\n@weave.op()\ndef extract_dinos(sentence: str) -> dict:\n    \"\"\"Extracts dinosaur names and diets from a sentence using OpenAI.\"\"\"\n    response = client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[\n            {\"role\": \"system\", \"content\": \"In JSON format extract a list of `dinosaurs`, with their `name`, their `common_name`, and whether its `diet` is a herbivore or carnivore.\"},\n            {\"role\": \"user\", \"content\": sentence}\n        ],\n        response_model=dict # Placeholder if a Pydantic model is not used here\n    )\n    return response.choices[0].message.content if response.choices else {}\n\n@weave.op()\ndef main():\n    sentence = \"The mighty Tyrannosaurus Rex (T-Rex), a carnivore, hunted the herbivorous Triceratops.\"\n    dinosaur_info = extract_dinos(sentence)\n    print(\"Extracted Dinosaur Info:\", dinosaur_info)\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"This quickstart demonstrates how to initialize Weave, decorate a function with `@weave.op` to trace its execution, and capture LLM interactions. It uses OpenAI as an example, requiring both W&B and OpenAI API keys."},"warnings":[{"fix":"Always verify the source and purpose of the 'weave' package; for AI/LLM use cases, it's `pip install weave` from Weights & Biases.","message":"There is an older, unrelated Python library also named 'weave' (scipy.weave) for embedding C/C++ code. Ensure you are installing and importing the 'weave' library from Weights & Biases for AI application development.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement a `to_dict()` method on custom objects or explicitly convert them to a dictionary of strings (e.g., `{'key': str(obj_value)}`) before they are passed to Weave operations.","message":"Custom Python objects in Weave traces might be truncated if not explicitly converted. For full data retention of complex objects, ensure they are converted into a dictionary of strings before logging.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to version 3.10 or newer.","message":"Weave requires Python 3.10 or higher. Older Python versions are not supported.","severity":"breaking","affected_versions":"<3.10"},{"fix":"To force exceptions to be re-raised during execution, set the `__should_raise=True` parameter when calling an `@weave.op` decorated function (e.g., `my_op.call(__should_raise=True)`).","message":"Weave's `.call()` method captures exceptions by default, storing them in `call.exception` rather than re-raising. This can obscure immediate error feedback.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set the `WANDB_API_KEY` environment variable or pass `api_key` to `weave.init()` (though environment variables are recommended for security) before running Weave-enabled code.","message":"Full functionality and logging require authentication with a Weights & Biases account. Your W&B API key must be provided.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}