← All ivy-nodes
IVYXSTUDIO · IVY NODE
J
JSON Prompt Creator
ivy.node.json-prompt-creator · v0.0.0
ivyx✓
Creates a JSON-formatted prompt function that formats context and question as a JSON string. The function returns a JSON object with 'context' and 'question' keys. This format is useful for structured data processing or when the LLM needs to parse the prompt as JSON. The output prompt_creator is used with prompt-generator node.
#json#prompt#creator
Inputs
| Field | Type | Description |
|---|---|---|
| features | object | Features |
| labels | object | Labels |
Outputs
| Field | Type | Description |
|---|---|---|
| prompt_creatorrequired | object | Callable function reference |
| features | object | Features |
| labels | object | Labels |
Source
python
# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
# Compute
class JSONPromptCreator:
"""Builds a JSON-style prompt-formatting callable."""
def build(self):
def json_prompt_creator(context: str, question: str, **kwargs) -> str:
return f"""{{
"context": "{context}",
"question": "{question}"
}}"""
return json_prompt_creator
creator_node = JSONPromptCreator()
prompt_creator = creator_node.build()
# Output collection (runner reads __ivy_ctx__)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out["prompt_creator"] = prompt_creatorTests
Requires: python:3.11
- basic-json-creator
Create JSON prompt creator function (should succeed).
jsonprompt-creatorbasic