Jons leads to llms: Practical guide with examples of Python coding

JSON promotes the order of planning orders in AI models using the JavaScript Acation (JSON) format, making clear, clear, machine reading. Unlike the promotion of the traditional text, which is in the mysterious language, JSON promotes services such as key-vaing Pairs, Arrays, and outstanding applications into the exact model texts to follow. This method is very improving consistency and accuracy – especially complex or repetitive activities – by allowing users to specify things such as type of work, topic, and other forms in a formal way that planrals. As AI systems are increasingly relying on the preceded, JSON's transparency systems, reliable results in large, including GPT-4, Claude, and Gemini.
In this lesson, we will move on to JSON's power to encourage and why it can change your way to AI models.
We will attend the benefits of using JSON to priorify examples of unlessing the alternative text. At the end, you will clearly see how organized adjourns breeds the accuracy, consistency and disability of your travel, whether you releases summaries, issuing data, or building advanced Ai. Look Full codes here.

To include leaning
import os
from getpass import getpass
os.environ["OPENAI_API_KEY"] = getpass('Enter OpenAI API Key: ')
Finding the Opelai API key, visit and generate a new key. If you are a new user, you may need to add payment information and make a minimum payment of $ 5 to activate API access. Look Full codes here.
from openai import OpenAI
client = OpenAI()
Structured motivation confirms consistency
Using a formal design, such as JSON based format, forcing you to think about fields and heritage – real profit when working with llms. Look Full codes here.
By explaining the planned formation, you finish cunning and guessing, to ensure that all the answer follows a visible pattern.
Here is a simple example:
Summarize the following email and list the action items clearly.
Email:
Hi team, let's finalize the marketing plan by Tuesday. Alice, prepare the draft; Bob, handle the design.
We will feed this in two ways and compare the results issued by the free comparisons of formal comparisons (JSS-based) to look at the difference in clarification and change. Look Full codes here.
Free-Form Prompt
prompt_text = """
Summarize the following email and list the action items clearly.
Email:
Hi team, let's finalize the marketing plan by Tuesday. Alice, prepare the draft; Bob, handle the design.
"""
response_text = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": prompt_text}]
)
text_output = response_text.choices[0].message.content
print(text_output)
Summary:
The team needs to finalize the marketing plan by Tuesday. Alice will prepare the draft, and Bob will handle the design.
Action items:
- Alice: Prepare the draft of the marketing plan by Tuesday.
- Bob: Handle the design by Tuesday.
- Team: Finalize the marketing plan by Tuesday.
JSON Early
prompt_json = """
Summarize the following email and return the output strictly in JSON format:
{
"summary": "short summary of the email",
"action_items": ["task 1", "task 2", "task 3"],
"priority": "low | medium | high"
}
Email:
Hi team, let's finalize the marketing plan by Tuesday. Alice, prepare the draft; Bob, handle the design.
"""
response_json = client.chat.completions.create(
model="gpt-5",
messages=[
{"role": "system", "content": "You are a precise assistant that always replies in valid JSON."},
{"role": "user", "content": prompt_json}
]
)
json_output = response_json.choices[0].message.content
print(json_output)
{
"summary": "Finalize the marketing plan by Tuesday; Alice to draft and Bob to handle design.",
"action_items": [
"Alice: prepare the draft",
"Bob: handle the design",
"Team: finalize the marketing plan by Tuesday"
],
"priority": "medium"
}
In this example, the use of a quick quick Jon is leading to clear and easy short disconnection and exploration. By explaining the fields such as “Summary”, “Action_A Customer Instead of Productive Text, which can be automatically improving the Ambigency and Requesting.
The user can control outgoing
If you plan your rapid EJSON, remove mysteriously from both instruction and output. In this example, requesting a summary of the market, emotions, opportunities, risk, and confidential scores can produce non-compliant formats as the transparent text. However, by building a request in JSON – the implicit fields like “the” feeling “,” risk “This is consistent. Look Full codes here.
Free-Form Prompt
plain_text_prompt = """
Analyze the following market update:
Market Text:
Tesla's Q2 earnings beat expectations due to higher Model Y sales, but rising competition from BYD is a risk.
Apple reported steady revenue growth driven by iPhone sales, but services revenue slightly declined.
Amazon's AWS division continues to dominate cloud computing, though regulatory scrutiny in Europe is increasing.
Generate:
- A 2-line market summary
- Sentiment for each company (positive, negative, neutral)
- Key growth opportunities and risks
- A confidence score from 0 to 10
"""
response_plain = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": plain_text_prompt}]
)
plain_output = response_plain.choices[0].message.content
print(plain_output)
Market summary:
- Earnings updates skew constructive: Tesla beat on Q2 with strong Model Y, Apple grew on iPhone, and AWS remains the cloud leader.
- Offsetting risks include BYD pressure on Tesla, Apple's services dip, and rising European scrutiny on Amazon.
Sentiment:
- Tesla: Positive
- Apple: Neutral
- Amazon: Positive
Key growth opportunities and risks:
- Tesla
- Opportunities: Sustain Model Y momentum; scale production and pricing to drive volume.
- Risks: Intensifying competition from BYD could pressure share and margins.
- Apple
- Opportunities: Monetize large iPhone base; re-accelerate services via bundles and ecosystem engagement.
- Risks: Services softness; dependence on iPhone for top-line growth.
- Amazon (AWS)
- Opportunities: Leverage leadership to win more enterprise/AI workloads and multi-year commitments.
- Risks: European regulatory scrutiny may lead to fines, compliance costs, or contract/pricing constraints.
Confidence score: 7/10
JSON Early
json_prompt = """
Analyze the following market update and return the response in this JSON format:
{
"summary": "2-line market overview",
"companies": [
{
"name": "string",
"sentiment": "positive | negative | neutral",
"opportunities": ["list of opportunities"],
"risks": ["list of risks"]
}
],
"confidence_score": "integer (0-10)"
}
Market Text:
Tesla's Q2 earnings beat expectations due to higher Model Y sales, but rising competition from BYD is a risk.
Apple reported steady revenue growth driven by iPhone sales, but services revenue slightly declined.
Amazon's AWS division continues to dominate cloud computing, though regulatory scrutiny in Europe is increasing.
"""
response_json = client.chat.completions.create(
model="gpt-5",
messages=[
{"role": "system", "content": "You are a precise assistant that always outputs valid JSON."},
{"role": "user", "content": json_prompt}
]
)
json_output = response_json.choices[0].message.content
print(json_output)
{
"summary": "Markets saw mixed corporate updates: Tesla beat expectations on strong Model Y sales and AWS maintained cloud leadership.nHowever, Apple's growth was tempered by softer services revenue while Tesla and AWS face competition and regulatory risks.",
"companies": [
{
"name": "Tesla",
"sentiment": "positive",
"opportunities": [
"Leverage strong Model Y demand to drive revenue and scale production",
"Sustain earnings momentum from better-than-expected Q2 results"
],
"risks": [
"Intensifying competition from BYD",
"Potential price pressure impacting margins"
]
},
{
"name": "Apple",
"sentiment": "neutral",
"opportunities": [
"Build on steady iPhone-driven revenue growth",
"Revitalize Services to reaccelerate growth"
],
"risks": [
"Slight decline in services revenue",
"Reliance on iPhone as the primary growth driver"
]
},
{
"name": "Amazon (AWS)",
"sentiment": "positive",
"opportunities": [
"Capitalize on cloud leadership to win new enterprise workloads",
"Expand higher-margin managed services and deepen customer spend"
],
"risks": [
"Increasing regulatory scrutiny in Europe",
"Potential compliance costs or operational restrictions"
]
}
],
"confidence_score": 8
}
The fast-formed Form produced a useful summary but had no structure, providing the model too much liberty and making it difficult to round or combine the boundaries with information or combination.
On the contrary, JSON's outcome is not easy to easily easily process the low process – Dashboard, automated alerts, or data pipes – but also confirm the admission of answers. By explaining the fields before, users successfully directed the model to bring exactly what they need, reduces understanding and improving honesty. Look Full codes here.
JSON Trive Treptates templates dreptate, speed, and clean cleaning.
By describing the formal fields before, groups can produce consistent, formal-readable results, data connects, details, or applications, or apps without manual formatting. This estimating is not limited to accelerating the work of work but also confirms the reliable, repetitive effects, making partnerships and seamstream in all projects.


Look Full codes here and notes. Feel free to look our GITHUB page for tutorials, codes and letters of writing. Also, feel free to follow it Sane and don't forget to join ours 100K + ml subreddit Then sign up for Our newspaper.

I am the student of the community engineering (2022) from Jamia Millia Islamia, New Delhi, and I am very interested in data science, especially neural networks and their application at various locations.



