Tools for AI coding agents to validate and analyze Elixir code in LiveBooks and scripts.
This library provides Mix tasks and utilities designed specifically for LLM coding agents (like GitHub Copilot, Claude Code, Cursor) to validate, analyze, and document Elixir code. It helps AI agents ensure code quality, verify API usage, and generate comprehensive documentation.
When working with Large Language Model coding agents, you often need to:
- Validate LiveBook code - Ensure that LiveBook notebooks contain valid, executable code
- Verify API calls - Check that all module function calls actually exist at runtime
- Extract code from notebooks - Get clean, executable Elixir code from LiveBook markdown
- Generate API documentation - Create comprehensive API references for AI agents to understand your codebase
This library provides automated tools to accomplish all of these tasks.
Extracts executable Elixir code from LiveBook (.livemd) files, filtering out markdown examples.
Use Case: AI agents can extract code from LiveBooks for testing, validation, or execution.
# Extract code (outputs clean Elixir code)
mix livebook.extract path/to/notebook.livemd > extracted.exs
# Extract with analysis (includes module calls, aliases, etc.)
mix livebook.extract --include-analysis notebook.livemd > analysis.mdWhat it does:
- Parses LiveBook markdown files
- Extracts only executable code cells (filters out
force_markdownexamples) - Optionally analyzes AST for aliases and function calls
- Outputs clean code or detailed markdown analysis
Perfect for:
- Testing LiveBook code in CI/CD pipelines
- Validating notebook syntax before committing
- Analyzing dependencies and API usage in notebooks
Validates that all module function calls in your code actually exist at runtime.
Use Case: AI agents can verify code correctness by checking that all API calls are valid.
mix api.validateWhat it does:
- Scans all
.exsand.livemdfiles in your project - For LiveBooks, extracts executable code first
- Parses code into AST and extracts all module function calls
- Resolves aliases to full module names
- Uses runtime reflection to verify each function exists
- Reports invalid calls with file locations
Output example:
VALIDATION SUMMARY
================================================================================
Total files: 15
Valid files: 13 (86.7%)
Invalid files: 2 (13.3%)
INVALID API CALLS FOUND
================================================================================
π scripts/example.exs
β Invalid calls:
- NonExistent.Module.function
- Another.Bad.call
A more complex (real-world) example would be
Compiling 16 files (.ex)
Generated azure_amqp app
# Validating API calls (checking actual function existence)...
================================================================================
VALIDATION SUMMARY
================================================================================
Total files: 122
Valid files: 78 (63.9%)
Invalid files: 44 (36.1%)
================================================================================
INVALID API CALLS FOUND
================================================================================
π content/05_advanced_patterns.livemd
β Invalid calls:
- MyEventProcessor.start_link
- ResilientSend.send_with_retry
π content/azure_certificates.livemd
β Invalid calls:
- MicrosoftCerts.CompileHelpers.download_certs_for_pinning
...
π test/integration/service_bus/sync_api_test.exs
β Invalid calls:
- IntegrationConfig.fetch_jwt_token (β Azure.Amqp.Test.IntegrationConfig.fetch_jwt_token)
- IntegrationConfig.jwt_config! (β Azure.Amqp.Test.IntegrationConfig.jwt_config!)
π test/integration/service_bus/topics_test.exs
β Invalid calls:
- IntegrationConfig.sas_config! (β Azure.Amqp.Test.IntegrationConfig.sas_config!)
π test/integration/stream_receiver_integration_test.exs
β Invalid calls:
- Azure.Amqp.Test.IntegrationConfig.eventhub_config!
- Azure.Amqp.Test.IntegrationConfig.fetch_eventhub_jwt_token
- ConnectionHolder.get_connection (β Azure.Amqp.Test.ConnectionHolder.get_connection)
- IntegrationConfig.sas_config! (β Azure.Amqp.Test.IntegrationConfig.sas_config!)
- QueueFlusher.flush_queue (β Azure.Amqp.Test.QueueFlusher.flush_queue)
- TelemetryHelper.attach_minimal_handler (β Azure.Amqp.Test.TelemetryHelper.attach_minimal_handler)
- TelemetryHelper.detach_all (β Azure.Amqp.Test.TelemetryHelper.detach_all)
Perfect for:
- Pre-commit hooks to catch API errors
- CI/CD validation of code quality
- Ensuring LiveBook notebooks use valid APIs
- Detecting typos in module or function names
Generates comprehensive API reference documentation in markdown format.
Use Case: AI agents can generate up-to-date API documentation for understanding codebases.
mix api.referenceWhat it does:
- Introspects all public modules and functions in your application
- Organizes modules by category (configurable)
- Generates markdown documentation with:
- Module descriptions
- Function signatures
- Documentation from
@docattributes - Return types from
@spec
- Outputs to configurable file (default:
docs/api-reference.md)
Configuration in mix.exs:
def project do
[
# ... other settings ...
api_category_mappings: [
{~r/MyApp.Web/, "Web"},
{~r/MyApp.Core/, "Core"},
{~r/MyApp.Data/, "Data Access"},
{true, "Other"} # default category
],
api_reference_output_file: "docs/api-reference.md"
]
endPerfect for:
- Generating documentation for AI agents to learn your API
- Keeping API docs synchronized with code
- Creating reference material for development teams
- Automated documentation in CI/CD
# Azure Amqp - API Reference
Concise reference of all public modules and functions.
---
## Mix Tasks
### [`Mix.Tasks.Azure.Amqp.FlushQueue`](../lib/mix/tasks/azure/amqp/flush_queue.ex)
Flush all messages from an Azure Service Bus queue and its dead-letter queue.
- `Mix.Tasks.Azure.Amqp.FlushQueue.run/1`
## Authentication
### [`Azure.Amqp.Auth.CBS.Client`](../lib/azure/amqp/auth/cbs/client.ex)
Claims-Based Security (CBS) client for Azure AMQP authentication.
- `Azure.Amqp.Auth.CBS.Client.__struct__/0`
- `Azure.Amqp.Auth.CBS.Client.__struct__/1`
- `Azure.Amqp.Auth.CBS.Client.child_spec/1` - Returns a specification to start this module under a supervisor.
- `Azure.Amqp.Auth.CBS.Client.close/1` - Closes the CBS client and its links.
- `Azure.Amqp.Auth.CBS.Client.code_change/3`
- `Azure.Amqp.Auth.CBS.Client.handle_call/3`
- `Azure.Amqp.Auth.CBS.Client.handle_cast/2`
- `Azure.Amqp.Auth.CBS.Client.handle_continue/2`
- `Azure.Amqp.Auth.CBS.Client.handle_info/2`
- `Azure.Amqp.Auth.CBS.Client.init/1`
- `Azure.Amqp.Auth.CBS.Client.put_token/2` - Sends a security token for a resource to enable access.
- `Azure.Amqp.Auth.CBS.Client.start_link/1` - Starts a CBS client linked to a connection.
- `Azure.Amqp.Auth.CBS.Client.terminate/2`
- `Azure.Amqp.Auth.CBS.Client.terminate/3`
- `Azure.Amqp.Auth.CBS.Client.validate_datetime/1`
### [`Azure.Amqp.Auth.CBS.SasToken`](../lib/azure/amqp/auth/cbs/sas_token.ex)
Shared Access Signature (SAS) token generation for Azure Service Bus and Event Hubs.
- `Azure.Amqp.Auth.CBS.SasToken.from_connection_string/1`
- `Azure.Amqp.Auth.CBS.SasToken.from_connection_string/2` - Convenience function to generate a SAS token from a connection string.
- `Azure.Amqp.Auth.CBS.SasToken.generate/1` - Generates a SAS token for a resource.
- `Azure.Amqp.Auth.CBS.SasToken.parse_connection_string/1` - Parses an Azure Service Bus connection string.
...
## AMQP Types
### [`Azure.Amqp.Protocol.Types.Outcomes`](../lib/azure/amqp/protocol/types/outcomes.ex)
AMQP 1.0 delivery outcomes for message settlement.
- `Azure.Amqp.Protocol.Types.Outcomes.accepted/0` - Creates an Accepted outcome.
- `Azure.Amqp.Protocol.Types.Outcomes.decode/1` - Decodes an outcome from an AMQP described type.
- `Azure.Amqp.Protocol.Types.Outcomes.encode/1` - Encodes an outcome as AMQP binary data.
- `Azure.Amqp.Protocol.Types.Outcomes.modified/0`
- `Azure.Amqp.Protocol.Types.Outcomes.modified/1` - Creates a Modified outcome.
- `Azure.Amqp.Protocol.Types.Outcomes.received/2` - Creates a Received outcome (not terminal).
- `Azure.Amqp.Protocol.Types.Outcomes.rejected/0`
- `Azure.Amqp.Protocol.Types.Outcomes.rejected/1`
- `Azure.Amqp.Protocol.Types.Outcomes.rejected/2`
- `Azure.Amqp.Protocol.Types.Outcomes.rejected/3` - Creates a Rejected outcome with optional error information.
- `Azure.Amqp.Protocol.Types.Outcomes.released/0` - Creates a Released outcome.
## Internal
### [`Azure.Amqp.Application`](../lib/azure/amqp/application.ex)
OTP Application for Azure.Amqp.
- `Azure.Amqp.Application.start/2`
- `Azure.Amqp.Application.stop/1`
---
## How This Was Generated
This document was generated using CodeAnalysis.API.ReferenceGenerator:
1. Extract API structure using CodeAnalysis.API.Introspection
2. `:application.get_key/2` - List all application modules
3. `Module.__info__(:functions)` - Get exported functions for each module
4. `Code.fetch_docs/1` - Extract @doc documentation
5. Pattern matching on module names for categorizationShows how modules are categorized for documentation.
Use Case: Verify module organization before generating documentation.
mix docs.show_groupsWhat it does:
- Displays computed module groups based on
category_mappings - Shows which modules fall into which categories
- Helps verify documentation organization
Perfect for:
- Debugging category mappings
- Verifying module organization
- Understanding documentation structure
# Extract and test LiveBook code
mix livebook.extract notebook.livemd > /tmp/test.exs
elixir /tmp/test.exs
# Validate API calls
mix api.validate
# If both pass, commit!
git add notebook.livemd
git commit -m "Add working notebook"# Generate comprehensive API reference
mix api.reference
# The AI agent can now read docs/api-reference.md to understand your API
cat docs/api-reference.md# .github/workflows/validate.yml
- name: Validate LiveBook API calls
run: |
mix deps.get
mix compile
mix api.validate# Extract code with analysis
mix livebook.extract --include-analysis notebook.livemd > analysis.md
# Review module calls and dependencies
cat analysis.mdAdd to your mix.exs:
def deps do
[
{:llm_code_analysis, github: "chgeuer/llm_code_analysis"}
]
endThen run:
mix deps.get
mix compileConfigure allowed modules in mix.exs:
def project do
[
api_validation_allowed_modules: [
"MyApp", # Allow all MyApp.* modules
"TestHelper", # Allow TestHelper module
"CustomUtil" # Allow CustomUtil module
]
]
endBy default, all standard library modules are allowed (Enum, String, Map, etc.).
Configure categories and output:
def project do
[
api_category_mappings: [
{~r/Azure.ServiceBus/, "Service Bus"},
{~r/Azure.EventHubs/, "Event Hubs"},
{~r/Azure.Storage/, "Storage"},
{true, "Core"} # catch-all
],
api_reference_output_file: "docs/AZURE_API.md"
]
end- AI agents can automatically validate code before suggesting changes
- Ensure LiveBook examples actually work
- Catch API errors early
- AI agents can generate and maintain API documentation
- Keep docs synchronized with code changes
- Provide context for code understanding
- Extract and test notebook code in isolation
- Validate notebooks in CI/CD pipelines
- Ensure examples remain executable
- AI agents can read generated API references to understand codebases
- Learn available modules and functions
- Make better code suggestions based on actual APIs
- Understand what modules a LiveBook uses
- Identify external dependencies
- Plan code refactoring
This library includes:
-
CodeAnalysis.Livebook.Extractor- Extract code from LiveBook files- Uses
NimbleLivebookMarkdownExtractorfor robust parsing - AST-based alias and function call extraction
- Alias resolution
- Uses
-
CodeAnalysis.API.Validator- Validate API calls- Runtime reflection to check function existence
- Support for
.exsand.livemdfiles - Detailed error reporting
-
CodeAnalysis.API.ReferenceGenerator- Generate API docs- Module introspection
- Markdown formatting
- Category-based organization
-
CodeAnalysis.API.Introspection- API analysis utilities- Extract module and function information
- Parse documentation and specs
- Module categorization
VALIDATION SUMMARY
================================================================================
Total files: 24
Valid files: 24 (100.0%)
Invalid files: 0 (0.0%)
β
All files use valid public APIs!
# Extracted Code Analysis
**Source:** `notebook.livemd`
## Extracted Executable Code
```elixir
Mix.install([
{:req, "~> 0.5"}
])
data = Req.get!("https://api.example.com")
IO.inspect(data)β Code is syntactically valid Elixir
Mix.installReq.get!
**Built for AI coding agents to validate, analyze, and document Elixir code efficiently.**