chore(cli): add validate command (#7438)

add validate command

---------

Co-authored-by: Will Fu-Hinthorn <will@langchain.dev>
This commit is contained in:
William FH
2026-04-07 18:29:24 -07:00
committed by GitHub
co-authored by Will Fu-Hinthorn
parent 336ad1239b
commit 890147681d
4 changed files with 122 additions and 20 deletions
+42
View File
@@ -817,6 +817,48 @@ def dev(
)
# ---------------------------------------------------------------------------
# validate command
# ---------------------------------------------------------------------------
@OPT_CONFIG
@cli.command(help="✅ Validate the LangGraph configuration file.")
@log_command
def validate(config: pathlib.Path):
import json
try:
with open(config) as f:
raw_config = json.load(f)
except json.JSONDecodeError as e:
raise click.UsageError(f"Invalid JSON in {config}: {e.args[0]}") from None
# Check for unknown keys before validation so they show alongside any error.
unknown_warnings = langgraph_cli.config.get_unknown_keys(raw_config)
try:
config_json = langgraph_cli.config.validate_config_file(config)
except (click.UsageError, ValueError) as e:
click.secho(f"Error: {e}", fg="red", err=True)
if unknown_warnings:
click.echo(err=True)
for warning in unknown_warnings:
click.secho(f" warning: {warning}", fg="yellow", err=True)
raise SystemExit(1) from None
num_graphs = len(config_json.get("graphs", {}))
click.secho(
f"Configuration file {config} is valid. "
f"({num_graphs} graph{'s' if num_graphs != 1 else ''} found)",
fg="green",
)
if unknown_warnings:
click.echo()
for warning in unknown_warnings:
click.secho(f" warning: {warning}", fg="yellow")
# ---------------------------------------------------------------------------
# new command
# ---------------------------------------------------------------------------